Voltar aos PodcastsClaude
Claude Code subagents
Projetando subagentes eficazes
Now that you know how to create sub aents, let's look at patterns that lead to effective sub aents.
Agora que você sabe como criar subagentes, vamos ver os padrões que levam a subagentes eficazes.
First, let's get a better idea of how subit data in the sub aent config file is used.
Primeiro, vamos entender melhor como os dados de configuração do subagente são usados.
Whenever you send a message to the main context window agent, the name and description of each sub aent is included in the system prompt.
Sempre que você envia uma mensagem ao agente principal, o nome e a descrição de cada subagente são incluídos no system prompt.
So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.
Então, se quiser controlar melhor quando o agente principal lança um subagente automaticamente, você deve modificar o nome e a descrição.
Next, remember that when a sub agent is launched, the main agent writes an input prompt.
Lembre-se também que, quando um subagente é iniciado, o agente principal escreve um prompt de entrada.
When writing this input prompt, it uses the description as guidance.
Ao escrever esse prompt de entrada, ele usa a descrição como guia.
So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.
Portanto, se quiser controlar melhor quando o agente principal lança um subagente automaticamente, você deve modificar o nome e a descrição.
Let's consider our review sub aent again.
Vamos considerar nosso subagente de revisão novamente.
Right now, when the main agent runs this sub agent, the sub aent is given an input prompt telling it to use get diff to find the current changes.
Agora, quando o agente principal executa esse subagente, o subagente recebe um prompt de entrada dizendo para usar o git diff para encontrar as mudanças atuais.
If we wanted the main agent to more reliably tell the sub agent exactly which files to review, we would update the description.
Se quiséssemos que o agente principal informasse ao subagente exatamente quais arquivos revisar de forma mais confiável, atualizaríamos a descrição.
You must tell the agent precisely which files you want it to review.
Você precisa informar ao agente precisamente quais arquivos quer que ele revise.
Now, if we ask claw to run the code reviewer agent, we'll see a different input.
Agora, se pedirmos ao Claude para executar o agente revisor de código, veremos uma entrada diferente.
You can also influence what the main thread tells a sub agent through the description.
Você também pode influenciar o que a thread principal diz a um subagente por meio da descrição.
So adding return sources that can be cited to a web search sub aents description causes the main thread to include that instruction when delegating the task.
Assim, adicionar "retorne fontes que possam ser citadas" à descrição de um subagente de busca na web faz com que a thread principal inclua essa instrução ao delegar a tarefa.
The most important improvement that you can make is defining an output format in the system prompt.
A melhoria mais importante que você pode fazer é definir um formato de saída no system prompt.
This creates natural stopping points for the sub aent.
Isso cria pontos de parada naturais para o subagente.
Without a defined output format, sub aents struggle to decide when enough research has been done and they tend to run much much longer than sub agents that are given an output format.
Sem um formato de saída definido, os subagentes têm dificuldade em decidir quando a pesquisa é suficiente e tendem a rodar muito mais tempo do que os que têm um formato de saída.
When a sub agent discovers a workaround to some issue like solving a dependency issue or finding that a certain command needs particular flags, these details should appear in the summary.
Quando um subagente descobre uma solução alternativa para algum problema, como resolver uma dependência ou encontrar que um comando precisa de flags específicas, esses detalhes devem aparecer no resumo.
Otherwise, the main thread has to rediscover the same solutions, obstacles encountered, any setup issues, workarounds discovered or environment quirks, commands that needed special flags or configuration, dependencies or imports that cause problems.
Caso contrário, a thread principal terá que redescobrir as mesmas soluções: obstáculos encontrados, problemas de configuração, soluções alternativas descobertas, peculiaridades do ambiente, comandos que precisavam de flags especiais e dependências ou imports que causaram problemas.
Explicitly asking for obstacle reporting in the output format surfaces this information.
Pedir explicitamente o reporte de obstáculos no formato de saída torna essa informação visível.
A readonly sub aent using just glob grap read cannot accidentally modify files.
Um subagente somente leitura que usa apenas glob, grep e read não pode modificar arquivos acidentalmente.
This constraint clarifies that the sub aents role and prevents unintended side effects.
Essa restrição esclarece o papel do subagente e evita efeitos colaterais indesejados.
So think about what sub aents actually needs to do.
Então pense no que o subagente realmente precisa fazer.
If it's just researching it only needs to read files.
Se ele está apenas pesquisando, só precisa ler arquivos.
So keep it read only.
Então mantenha-o somente leitura.
That way it can't accidentally modify anything while exploring.
Assim ele não pode modificar nada acidentalmente enquanto explora.
A reviewer needs to run get diff to see what changed.
Um revisor precisa rodar o git diff para ver o que mudou.
So give it bash access, but it still doesn't need to edit files.
Então dê acesso ao bash, mas ele ainda não precisa editar arquivos.
Only give edit and write to sub aents that should actually change your code, like a styling agent applying CSS updates.
Só dê acesso a edit e write para subagentes que devem realmente alterar seu código, como um agente de estilo aplicando atualizações CSS.
This also helps clarify what each sub aent is for when you have several of them.
Isso também ajuda a esclarecer para que serve cada subagente quando você tem vários deles.
So effective sub aents use structured output report obstacles have specific descriptions and limit tool access.
Portanto, subagentes eficazes usam saída estruturada, reportam obstáculos, têm descrições específicas e limitam o acesso a ferramentas.