Skip to main content
Deep agents can create subagents to delegate work. You can specify custom subagents in the subagents parameter. Subagents are useful for context quarantine (keeping the main agent’s context clean) and for providing specialized instructions.

Why use subagents?

Subagents solve the context bloat problem. When agents use tools with large outputs (web search, file reads, database queries), the context window fills up quickly with intermediate results. Subagents isolate this detailed work—the main agent receives only the final result, not the dozens of tool calls that produced it. When to use subagents:
  • ✅ Multi-step tasks that would clutter the main agent’s context
  • ✅ Specialized domains that need custom instructions or tools
  • ✅ Tasks requiring different model capabilities
  • ✅ When you want to keep the main agent focused on high-level coordination
When NOT to use subagents:
  • ❌ Simple, single-step tasks
  • ❌ When you need to maintain intermediate context
  • ❌ When the overhead outweighs benefits

Configuration

subagents should be a list of dictionaries or CompiledSubAgent objects. There are two types:

SubAgent (Dictionary-based)

For most use cases, define subagents as dictionaries: Required fields:
  • name (str): Unique identifier for the subagent. The main agent uses this name when calling the task() tool.
  • description (str): What this subagent does. Be specific and action-oriented. The main agent uses this to decide when to delegate.
  • system_prompt (str): Instructions for the subagent. Include tool usage guidance and output format requirements.
  • tools (List[Callable]): Tools the subagent can use. Keep this minimal and include only what’s needed.
Optional fields:
  • model (str | BaseChatModel): Override the main agent’s model. Use the format "provider:model-name" (for example, "openai:gpt-4o").
  • middleware (List[Middleware]): Additional middleware for custom behavior, logging, or rate limiting.
  • interrupt_on (Dict[str, bool]): Configure human-in-the-loop for specific tools. Requires a checkpointer.

CompiledSubAgent

For complex workflows, use a pre-built LangGraph graph: Fields:
  • name (str): Unique identifier
  • description (str): What this subagent does
  • runnable (Runnable): A compiled LangGraph graph (must call .compile() first)

Using SubAgent

Using CompiledSubAgent

For more complex use cases, you can provide your own pre-built LangGraph graph as a subagent:

The general-purpose subagent

In addition to any user-defined subagents, deep agents have access to a general-purpose subagent at all times. This subagent:
  • Has the same system prompt as the main agent
  • Has access to all the same tools
  • Uses the same model (unless overridden)

When to use it

The general-purpose subagent is ideal for context isolation without specialized behavior. The main agent can delegate a complex multi-step task to this subagent and get a concise result back without bloat from intermediate tool calls.

Example

Instead of the main agent making 10 web searches and filling its context with results, it delegates to the general-purpose subagent: task(name="general-purpose", task="Research quantum computing trends"). The subagent performs all the searches internally and returns only a summary.

Best practices

Write clear descriptions

The main agent uses descriptions to decide which subagent to call. Be specific: Good: "Analyzes financial data and generates investment insights with confidence scores" Bad: "Does finance stuff"

Keep system prompts detailed

Include specific guidance on how to use tools and format outputs:

Minimize tool sets

Only give subagents the tools they need. This improves focus and security:

Choose models by task

Different models excel at different tasks:

Return concise results

Instruct subagents to return summaries, not raw data:

Common patterns

Multiple specialized subagents

Create specialized subagents for different domains:
Workflow:
  1. Main agent creates high-level plan
  2. Delegates data collection to data-collector
  3. Passes results to data-analyzer
  4. Sends insights to report-writer
  5. Compiles final output
Each subagent works with clean context focused only on its task.

Troubleshooting

Subagent not being called

Problem: Main agent tries to do work itself instead of delegating. Solutions:
  1. Make descriptions more specific:
  2. Instruct main agent to delegate:

Context still getting bloated

Problem: Context fills up despite using subagents. Solutions:
  1. Instruct subagent to return concise results:
  2. Use filesystem for large data:

Wrong subagent being selected

Problem: Main agent calls inappropriate subagent for the task. Solution: Differentiate subagents clearly in descriptions:

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.