Subagents — task division and context isolation
Subagents — task division and context isolation
When a large task is handed to one LLM instance in a single shot, the context fills quickly and responsibility blurs. Subagents are the pattern of slicing a task into smaller units and delegating each to a separate model instance. The motivation is context savings, parallelism, and role separation; the cost is debugging and message design.
1. About subagents
A subagent is used in these senses:
- A helper agent that a parent agent (or host) calls to perform a specific task.
- Has its own system prompt, tools, and session.
- Returns a result back to the parent (usually text or structured data).
The parent calls the subagent like a tool call. The fact that the call argument can be a natural-language task instruction is what differs from ordinary function calls.
2. Tool examples
- Claude Code's Agent tool — invoked with
subagent_typeto specify the kind. Per-role types likegeneral-purpose·code-reviewer. - LangGraph's supervisor pattern — a parent node routes to child nodes.
- AutoGen's GroupChat / SwarmChat — multi-agent dialogue.
- CrewAI's Crew · Agent — role-based collaboration.
- Google ADK's Hierarchical Agent — parent-child delegation.
The names and interfaces differ across tools, but the core idea is similar.
3. Call flow
[Parent] analyze user intent
↓
instruction like "review the code change" + context bundle
↓
[Child] own system prompt + received instruction + tool use
↓
result (summary · checklist · structured data)
↓
[Parent] integrate result · decide next step
The parent doesn't see the child's internal reasoning in full. It receives only the result and uses it for the next decision.
4. The effect of context isolation
- The child task's tool results and logs don't accumulate in the parent context.
- The number of messages the parent sees shrinks, improving inference stability.
- Some token cost goes down (overall cost is parent + child combined).
In exchange, results may be lost in the summarization step.
5. Pattern comparison
| Pattern | Shape |
|---|---|
| Supervisor (router) | Parent decides which child to send to. |
| Pipeline | Children work sequentially (search → write → review). |
| Parallel | Independent children run simultaneously and merge. |
| Loop | Repeat until termination condition. |
| Hierarchy | Multi-layer tree. |
6. Multi-agent vs single agent
An actively debated place. Many writings from Anthropic, Cognition, and others come up. Roughly summarized:
Multi advantages:
- Context partitioning.
- Per-role evaluation and replacement.
- Parallel processing.
Multi costs:
- The burden of message-passing design.
- Blurred lines of responsibility (where did the failure start).
- Increased cost and latency.
- Duplicate processing of the same information.
The decisive factors are whether the task is large enough and whether the sub-tasks are truly independent.
7. Other strands of context savings
| Strand | Note |
|---|---|
| Summarize tool results, store to memory | Store in external memory (vector · KV) and remove from context. |
| Message compression | Summarize old messages with the model into a single line. |
| Checkpoint · resume | Save intermediate state for the next session. |
| Cache (prompt caching) | Cache the same system and tool definitions to reduce cost and latency. |
| Use models with large context windows | 100k–1M token models reduce the need to split. |
Subagents can be combined with these.
8. Code-review assistant example
[Parent agent]
- parse user intent
- organize domain knowledge
- classify changes
- [Child: security review] (look at changed files only and list potential risks)
- [Child: test review] (missing tests · edge cases)
- [Child: doc review] (check docs that need updating)
- integrate results → single report to user
Research assistant:
[Parent] decompose user question → 5 sub-questions
[Children × 5 (parallel)] search and summarize per sub-question
[Parent] integrate · deduplicate · final answer
When long tool output (web pages, logs) isn't seen by the parent and the child summarizes and returns, the parent context stays light. The shape "raw text in external memory, only the essentials summarized."
9. Termination-condition design
To prevent subagents from getting stuck in infinite loops:
- Step caps (e.g., max N tool calls).
- Token and time caps.
- An explicit termination signal ("final answer" format).
- Parent-side timeout and interrupt.
10. Common pitfalls
Summary loss — when the child summarizes back, the parent can't see the details. Preserve some raw material for important cases.
Context duplication — when the parent passes a large context to each child, the point of splitting weakens.
Message-design burden — designing the parent-child interface (input/output formats) is its own work.
Error propagation — a single child mistake propagates and the parent uses it in the next step. Verification step needed.
Cost and latency growth — the sum of multi-calls can cost more than a single call.
Debugging difficulty — tracking which step went off is hard. Keep traces, logs, and session IDs consistent.
User-perception gap — the user sees it as "a single task asked of one agent" but multiple models are running internally and the response gets longer.
Non-determinism accumulation — non-determinism at each step compounds, shaking output quality. Per-step eval sets.
Closing thoughts
Subagents are a natural answer when context overflows, but if tasks aren't truly independent, the design burden grows. The "simplicity first" principle Anthropic's "Building effective agents" emphasizes — single agent + large context window + tool-result-summary memory — covers many places. Adopt subagents when independence and parallelism are clearly visible.
Next
- hooks-settings
- claude-md-pattern
We refer to LangGraph Multi-agent · Anthropic Building Effective Agents · AutoGen Multi-agent · Claude Code Subagents · CrewAI · Google ADK Multi-agent · GAIA.