Volver a PodcastsClaude
Claude Code subagents
Cómo diseñar subagentes efectivos
Now that you know how to create sub aents, let's look at patterns that lead to effective sub aents.
Ahora que sabes cómo crear subagentes, veamos los patrones que llevan a subagentes efectivos.
First, let's get a better idea of how subit data in the sub aent config file is used.
Primero, entendamos mejor cómo se utilizan los datos del archivo de configuración del subagente.
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.
Cada vez que envías un mensaje al agente principal de ventana de contexto, el nombre y la descripción de cada subagente se incluyen en el 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.
Para controlar mejor cuándo el agente principal lanza un subagente automáticamente, debes modificar el nombre y la descripción.
Next, remember that when a sub agent is launched, the main agent writes an input prompt.
A continuación, recuerda que cuando se lanza un subagente, el agente principal escribe una instrucción de entrada.
When writing this input prompt, it uses the description as guidance.
Al escribir esta instrucción de entrada, usa la descripción como guía.
So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.
Para controlar mejor cuándo el agente principal lanza un subagente automáticamente, debes modificar el nombre y la descripción.
Let's consider our review sub aent again.
Revisemos nuestro subagente de revisión.
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.
Ahora mismo, cuando el agente principal ejecuta este subagente, se le da una instrucción de entrada indicándole que use get diff para encontrar los cambios actuales.
If we wanted the main agent to more reliably tell the sub agent exactly which files to review, we would update the description.
Si quisiera que el agente principal indicara de forma más confiable al subagente exactamente qué archivos revisar, actualizaríamos la descripción.
You must tell the agent precisely which files you want it to review.
Debes indicarle al agente con precisión qué archivos quieres que revise.
Now, if we ask claw to run the code reviewer agent, we'll see a different input.
Ahora, si le pedimos a Claude que ejecute el agente de revisión de código, veremos una instrucción de entrada diferente.
You can also influence what the main thread tells a sub agent through the description.
También puedes influir en lo que el hilo principal le dice a un subagente a través de la descripción.
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.
Así, añadir devolver fuentes que puedan citarse a la descripción de un subagente de búsqueda web hace que el hilo principal incluya esa instrucción al delegar la tarea.
The most important improvement that you can make is defining an output format in the system prompt.
La mejora más importante que puedes hacer es definir un formato de salida en el system prompt.
This creates natural stopping points for the sub aent.
Esto crea puntos de parada naturales para el 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.
Sin un formato de salida definido, los subagentes tienen dificultades para decidir cuándo la investigación es suficiente y tienden a ejecutarse mucho más tiempo que los subagentes que tienen un formato de salida.
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.
Cuando un subagente descubre una solución alternativa a algún problema, como resolver una dependencia o encontrar que un comando necesita indicadores específicos, estos detalles deben aparecer en el resumen.
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.
De lo contrario, el hilo principal tiene que redescubrir las mismas soluciones: obstáculos encontrados, problemas de configuración, soluciones alternativas descubiertas, particularidades del entorno, comandos que necesitaron indicadores o configuración especial, dependencias o importaciones que causaron problemas.
Explicitly asking for obstacle reporting in the output format surfaces this information.
Pedir explícitamente un informe de obstáculos en el formato de salida hace que esta información emerja.
A readonly sub aent using just glob grap read cannot accidentally modify files.
Un subagente de solo lectura que usa únicamente glob, grep y read no puede modificar archivos accidentalmente.
This constraint clarifies that the sub aents role and prevents unintended side effects.
Esta restricción aclara el rol del subagente y evita efectos secundarios no deseados.
So think about what sub aents actually needs to do.
Piensa en lo que los subagentes realmente necesitan hacer.
If it's just researching it only needs to read files.
Si solo investiga, solo necesita leer archivos.
So keep it read only.
Manténlo en solo lectura.
That way it can't accidentally modify anything while exploring.
Así no puede modificar nada accidentalmente mientras explora.
A reviewer needs to run get diff to see what changed.
Un agente de revisión necesita ejecutar get diff para ver qué cambió.
So give it bash access, but it still doesn't need to edit files.
Dale acceso bash, pero aún así no necesita editar archivos.
Only give edit and write to sub aents that should actually change your code, like a styling agent applying CSS updates.
Solo da edit y write a los subagentes que realmente deben cambiar tu código, como un agente de estilos que aplica actualizaciones CSS.
This also helps clarify what each sub aent is for when you have several of them.
Esto también ayuda a aclarar para qué sirve cada subagente cuando tienes varios de ellos.
So effective sub aents use structured output report obstacles have specific descriptions and limit tool access.
Los subagentes efectivos usan salidas estructuradas, reportan obstáculos, tienen descripciones específicas y limitan el acceso a herramientas.