Voltar aos PodcastsClaude
Claude Code subagents
Criando um subagente
In the previous video, we covered what sub aents are and how they work.
No vídeo anterior, vimos o que são subagentes e como eles funcionam.
Cloud code includes built-in sub aents, but you can also create your own sub aents that specialize in certain tasks.
Claude Code inclui subagentes integrados, mas você também pode criar seus próprios subagentes especializados em determinadas tarefas.
Custom sub aents are markdown files with YAML front matter.
Subagentes personalizados são arquivos Markdown com YAML front matter.
These markdown files contain configuration that helps claude understand when to use the sub aent and provides directions to the sub aent itself.
Esses arquivos Markdown contêm configurações que ajudam Claude a entender quando usar o subagente e fornecem instruções ao próprio subagente.
Now, the easiest way to create a sub agent is with the / agents command.
A maneira mais fácil de criar um subagente é com o comando /agents.
This panel is the main interface for managing your sub aents.
Esse painel é a interface principal para gerenciar seus subagentes.
Once here, select create new agent.
Aqui, selecione criar novo agente.
You'll then be asked if you want to create a sub aent for the current project or a sub aent that will be shared between all the projects on your machine.
Você será perguntado se deseja criar um subagente para o projeto atual ou um subagente compartilhado entre todos os projetos na sua máquina.
Next, you can create a sub aent manually, but we recommend using claw code to automatically generate it for you.
Você pode criar um subagente manualmente, mas recomendamos usar Claude Code para gerá-lo automaticamente.
Our first sub aent will be a code reviewer.
Nosso primeiro subagente será um revisor de código.
I'll ask Claude to make a sub agent that reviews code quality and security issues.
Vou pedir ao Claude para criar um subagente que revisa qualidade de código e problemas de segurança.
Claude will use your input to generate a name, description, and system prompt for the sub agent.
Claude usará sua entrada para gerar um nome, descrição e system prompt para o subagente.
We'll see those in a moment, but before we do, we get the opportunity to customize the tools that this sub agent has access to.
Veremos isso em breve, mas antes disso, temos a oportunidade de personalizar as ferramentas que esse subagente pode acessar.
Now, given that our sub agent is only responsible for reviewing code, you might decide to disallow tools for editing, but I'll leave an execution to allow the sub agent to more easily identify pending changes.
Como nosso subagente é responsável apenas por revisar código, você pode optar por desabilitar ferramentas de edição, mas vou manter a execução para permitir que o subagente identifique mudanças pendentes com mais facilidade.
Next, you'll be prompted to select the model that powers this sub agent.
Você será solicitado a selecionar o modelo que alimenta esse subagente.
And finally, a color.
E por fim, uma cor.
This color is used in the UI to help you better identify the sub agent.
Essa cor é usada na interface para ajudá-lo a identificar melhor o subagente.
And it also just adds a little bit of personal flare.
E também adiciona um toque pessoal.
Now at the summary window, we see that the sub aent config file will be saved into my current project at this path.
Na janela de resumo, vemos que o arquivo de configuração do subagente será salvo no projeto atual neste caminho.
Now let's open up that file to get a better idea of what's going on.
Agora vamos abrir esse arquivo para entender melhor o que está acontecendo.
The name field is a unique identifier.
O campo name é um identificador único.
This is how you reference the sub agent either by asking claw directly or using at agent code quality reviewer in your message.
É assim que você referencia o subagente, seja perguntando diretamente ao Claude ou usando @agent code quality reviewer na sua mensagem.
The description controls when cla decides to use the sub aent.
A descrição controla quando Claude decide usar o subagente.
The description must be on a single line.
A descrição deve estar em uma única linha.
Notice that there are escaped new line characters in there.
Note que há caracteres de nova linha escapados.
If you want Claude to use the sub agent automatically more often, add in the word proactively to the description.
Se você quiser que Claude use o subagente automaticamente com mais frequência, adicione a palavra proativamente à descrição.
You can also add example conversations to help Claude understand when it should be using the sub agent.
Você também pode adicionar conversas de exemplo para ajudar Claude a entender quando deve usar o subagente.
The tools field lists which tools the sub agent can access.
O campo tools lista quais ferramentas o subagente pode acessar.
The list of tools will match the tools we granted access to during the agent generation, but you can further edit the list of tools in this file if you want.
A lista de ferramentas corresponderá às ferramentas que concedemos acesso durante a geração do agente, mas você pode editar a lista neste arquivo se quiser.
The model field specifies which claw model to use.
O campo model especifica qual modelo Claude usar.
Sonnet, opus, haiku or inherit.
Sonnet, opus, haiku ou inherit.
Use haiku for fast tasks.
Use haiku para tarefas rápidas.
Opus for complex analysis and sonnet if you need something between the two.
Opus para análises complexas e sonnet se precisar de algo entre os dois.
Inherit will use the same model as your main conversation.
Inherit usará o mesmo modelo da sua conversa principal.
The body of the file contains the system prompt that is given to the sub aent.
O corpo do arquivo contém o system prompt fornecido ao subagente.
The system prompt will provide guidance to the sub agent, helping it understand how to complete its task and how it should return information back to the main agent.
O system prompt orienta o subagente, ajudando-o a entender como concluir sua tarefa e como retornar informações ao agente principal.
Now for the fun part.
Agora a parte divertida.
After creating your sub agent, test it by making some code changes and asking claw to review them.
Após criar seu subagente, teste-o fazendo algumas alterações no código e pedindo ao Claude para revisá-las.
If the sub agent isn't being used when you expect, check your description.
Se o subagente não estiver sendo usado quando esperado, verifique sua descrição.
Adding more specific examples helps Claude understand when to delegate.
Adicionar exemplos mais específicos ajuda Claude a entender quando delegar.