Domain 1 · Task 1.3
Subagent Invocation & Context Passing
Configure subagent invocation, context passing, and spawning.
Subagents are spawned with the Task tool (the coordinator's allowedTools must include "Task"). Each subagent starts with a fresh, isolated context — it does *not* inherit the coordinator's conversation, prior tool results, or memory. The recurring exam idea is simple and unforgiving: if a subagent needs a piece of information, you have to put it in the prompt, because context is *passed*, never *inherited*.
Key concept
If a subagent needs it, put it in the prompt. Context is passed explicitly, never inherited — there is no shared memory across invocations.
What you need to know
Spawning with the Task tool
The Task tool spawns subagents, so the coordinator's allowedTools must include "Task" or it cannot delegate at all. An AgentDefinition configures each subagent: its description, its system prompt, and its tools (tool restrictions per role). To run subagents in parallel, emit multiple Task calls in a single response — serializing independent subagents across separate turns wastes wall-clock time for no benefit.
Context is passed, never inherited
A subagent cannot see the coordinator's conversation or the results other subagents produced. That means you must include the complete prior findings directly in the subagent's prompt — for example, passing the web-search results *and* the document analysis into a synthesis subagent's prompt. The classic bug is a synthesis agent that "lacks the search results": the cause is never that it forgot, it is that the context was never passed to it. Assuming subagents "remember" the coordinator, or handing them a bare task with no data, both break for the same reason.
synthesis_prompt = f"""Synthesize a report from these findings.
<web_results>
{web_results}
</web_results>
<document_analysis>
{doc_analysis}
</document_analysis>
Goal: a cohesive report with sources cited. Quality bar: every claim
attributed to a source URL or document name."""
# Parallel fan-out: multiple Task calls in ONE response
tasks = [
Task(agent="researcher", prompt=topic_a_prompt),
Task(agent="researcher", prompt=topic_b_prompt),
]Preserve attribution across hops
Because each hop is a fresh context, provenance is easy to lose. Use structured data formats that separate content from metadata — source URLs, document names, page numbers — so attribution survives from the researcher to the synthesizer. If you flatten everything into prose before handing it off, the next subagent cannot cite anything and citations silently disappear during synthesis.
Specify goals, not procedures
Write coordinator prompts that state goals and quality criteria, not rigid step-by-step procedures. Over-specifying the exact steps prevents the subagent from adapting to what it actually finds — the opposite of what you want from an autonomous agent. Tell it *what good looks like* and let it reason about *how* to get there.
Exam traps
| The trap | The reality |
|---|---|
| Subagents inherit the coordinator's conversation and remember earlier findings. | Subagents start with isolated context and inherit nothing. Anything they need must be included explicitly in their prompt. |
| The synthesis agent lacks the search results because of a bug or a memory limit. | The results were simply never passed. Put the web results and document analysis directly into the synthesis prompt. |
| To run several subagents in parallel you spawn one per turn across multiple responses. | Parallelism comes from emitting multiple Task calls in a single response. Serializing independent subagents is wasteful. |
| Detailed step-by-step instructions make subagents more reliable. | Over-specified procedures prevent adaptation. Specify goals and quality criteria so subagents can adjust to what they discover. |
Practice scenario
Real questions from the bank that test this topic — the correct answer is highlighted.
You're building a Claude Code workflow where complex refactoring tasks should be delegated to a specialized "refactor-expert" agent with its own isolated context, restricted to Read/Edit/ Glob tools, and using a more powerful model than the default. The main agent should invoke this delegation automatically when refactoring is needed — no explicit user command.
What's the correct implementation?
refactor-expert.md with YAML frontmatter ( name , description , tools , model ); Claude will route appropriate tasks to it automatically based on the descriptionCorrectCLAUDE.md instruction telling Claude to "act as a refactoring expert" when refactoring tasks come upWhy: Claude Code subagents are defined as markdown files in .claude/agents/<name>.md with YAML frontmatter: name , description , tools , model . The description field is what drives automatic delegation — when the main agent recognizes a task matching the description, it delegates without explicit user invocation. Slash commands (B) require explicit /command invocation. Subprocess piping (C) is brittle and outside the SDK integration. CLAUDE.md instructions (D) tell Claude how to behave but don't create a separate-context agent with its own tool restrictions and model.
You're building a multi-agent research system where a coordinator delegates work to four specialized subagents. After implementation, you notice the synthesis subagent often fails with "no research findings provided" even though the web search and document analysis subagents completed successfully on the prior turn.
What is the most likely cause?
Why: Subagents operate with isolated context — they do not automatically inherit the coordinator's conversation history or sibling subagents' outputs (Task Statement 1.3). The coordinator must explicitly include prior findings in the synthesis subagent's prompt. Option A ( allowedTools missing "Task" ) is plausible — that would cause spawning to fail silently — but the symptom here is "no findings provided," which is the prompt-content problem. Option C confuses tool restrictions with context inheritance. Option D wrongly suggests subagents inherit coordinator history.
Build exercise
Wire up a coordinator that passes context explicitly
~50 min- 1Give the coordinator
allowedToolsthat include"Task", and define twoAgentDefinitions: a researcher (web tools) and a synthesizer (no web tools).Why: Without
Taskin allowedTools the coordinator cannot spawn anyone; role-scoped tools keep each subagent focused. - 2Fan out two researcher subagents on distinct subtopics by emitting both
Taskcalls in one response.You should see: Both researchers run in parallel rather than one-after-another across turns.
- 3Collect their outputs in a structured form that keeps each claim next to its source URL and document name.
Why: Separating content from metadata is what lets attribution survive the hand-off.
- 4Build the synthesis prompt by embedding the full researcher findings inside it, then spawn the synthesizer.
You should see: The synthesizer produces a cited report — because the results are in its prompt, not assumed to be inherited.
- 5Now delete the findings from the synthesis prompt and re-run to reproduce the "synthesis agent has no data" failure.
Why: Seeing the failure firsthand cements that context is passed, never inherited.
Sources
Drill Agentic Architecture & Orchestration
Practice only this domain’s questions, untimed, with instant explanations.