A\
Lessons/Domain 1
1.312 min

Configure subagent invocation, context passing, and spawning

In multi-agent systems built on the Claude Agent SDK, a coordinator spawns subagents with the Task tool, and every subagent starts with a blank context window. Production reliability depends on three decisions: giving the coordinator the Task tool, passing all required findings explicitly into each subagent prompt with structured source metadata, and choosing correctly between parallel spawning, goal-oriented delegation, and session forking. Getting these wrong causes lost attribution, silent context gaps, and needless serial latency that a correct design avoids.

Coordinator agentallowedTools has Taskone response = two Task calls (run in parallel)Task: web-searchtools: WebSearch, WebFetchisolated context: inherits nothingreturns claim + url + dateTask: doc-analysistools: Read, Grepisolated context: inherits nothingreturns claim + source + pagefindings passed explicitly in the synthesis promptTask: synthesisgets both agents outputs in promptpreserves source attributionWhy explicit passing mattersSubagents share no memory. If a finding is not in the prompt, the subagentcannot see it. Structured records (claim, source url, document, page, date)keep attribution intact so synthesis can cite sources correctly.
Coordinator spawning parallel subagents via Task, with isolated contexts and explicit structured context passing into synthesis.

Spawning subagents: the Task tool and allowedTools

Subagents are spawned through the built-in Task tool. When the coordinator wants to delegate work, it emits a Task tool call describing the subagent to run and the prompt to give it. The Agent SDK then launches that subagent, runs its own agentic loop to completion, and returns its final output back to the coordinator as the tool result.

The hard requirement to memorize: the coordinator can only spawn subagents if "Task" is present in its allowedTools. If Task is not allowed, the coordinator has no mechanism to delegate and will try to do everything itself in a single context, which defeats the entire coordinator-subagent architecture.

In the SDK you configure this on the top-level query, and you define the available subagent types in an agents map:

const result = query({
  prompt: 'Research the impact of AI on creative industries',
  options: {
    allowedTools: ['Task'],            // required to spawn subagents
    agents: {
      'web-search': { /* AgentDefinition */ },
      'doc-analysis': { /* AgentDefinition */ },
      'synthesis': { /* AgentDefinition */ }
    }
  }
});

In Claude Code the same subagents can also be declared as Markdown files in .claude/agents/ with YAML frontmatter (name, description, tools, model) plus a system-prompt body. Either way, the coordinator still needs Task in its allowed tools to invoke them.

Isolated context: subagents inherit nothing

This is the single most tested idea in this task statement. A subagent runs in its own isolated context window. It does not inherit the coordinator's conversation history, it cannot see what other subagents produced, and it shares no memory between separate invocations. Each Task call is effectively a fresh conversation seeded only by the prompt you hand it.

The practical consequence: if a piece of information is not written into the subagent's prompt, the subagent simply cannot access it. A synthesis subagent will not magically know the web search results or the document analysis output unless the coordinator copies those findings into the synthesis prompt. There is no ambient shared state.

This is intentional and beneficial. Isolation keeps each subagent's context lean and focused, avoids attention dilution from irrelevant history, and lets subagents run in parallel without interfering with one another. But it shifts responsibility onto the coordinator to be explicit and complete about what it passes down.

AgentDefinition: description, system prompt, tool restrictions

Each subagent type is configured with an AgentDefinition. The three fields you must know are the description, the system prompt, and the tools restriction (an optional model can also be set to trade cost for capability).

The description behaves like a tool description: it is what the coordinator reads when deciding which subagent fits the current need, so it should clearly state the subagent's purpose and when to use it. The prompt is the subagent's system prompt, establishing its role, behavior, and output expectations. The tools field scopes what the subagent may call, which prevents cross-specialization misuse (for example, a synthesis agent should not be able to run web searches).

agents: {
  'web-search': {
    description: 'Finds and extracts web sources. Use for locating articles, data, and current information.',
    prompt: 'You are a web research specialist. Return each finding as a claim with its source URL and publication date.',
    tools: ['WebSearch', 'WebFetch'],
    model: 'sonnet'
  }
}

Good descriptions and tight tool lists are how you get the coordinator to route work to the right subagent and how you keep each subagent reliable within its lane.

Passing context explicitly with structured formats

Because subagents inherit nothing, the coordinator must include the complete findings from prior agents directly in the next subagent's prompt. For the synthesis subagent, that means embedding the actual web search results and document analysis outputs, not a reference to them and not a vague summary that drops the numbers.

Critically, pass this context in a structured format that separates content from metadata. Every claim should travel with its provenance (source URL, document name, page number, publication date) so attribution survives the handoff. If you flatten findings into one prose blob, the synthesis agent loses the ability to cite sources and may misattribute or fabricate references.

{
  "claim": "Generative music tools cut demo production time by roughly 60%",
  "source_url": "https://example.com/music-ai-report",
  "document": "Sound and Tech Annual 2025",
  "page": 14,
  "published": "2025-03-01"
}

Keeping claim, source, and date in discrete fields (rather than merged into a sentence) is what lets a downstream agent preserve citations, distinguish well-supported claims from weak ones, and treat differing dates as temporal context rather than contradictions.

Parallel spawning vs sequential turns

To run subagents in parallel, the coordinator emits multiple Task tool calls in a single assistant response. The SDK runs those spawned subagents concurrently and returns all their results together. This is the correct way to fan out independent work such as searching several source types at once.

If instead the coordinator emits one Task call per turn (spawn, wait for the result, then spawn the next in the following turn), those subagents run sequentially, one after another. That is the right shape only when a later subagent genuinely depends on an earlier one's output (for example, synthesis must wait for search and analysis to finish).

The exam framing is precise: parallelism comes from batching multiple Task calls in one response, not from any special flag or configuration. When independent subagents are forced across separate turns, you pay avoidable latency. When dependent steps are wrongly parallelized, you get incomplete inputs. Match the emission pattern to the actual dependency graph.

Goal-oriented coordinator prompts

Design coordinator prompts (and the delegated subagent prompts) to specify research goals and quality criteria rather than step-by-step procedural instructions. Tell the subagent what a good result looks like and what to cover, not a rigid script of exact actions to take in order.

Goal-oriented delegation lets each subagent adapt its approach to what it actually discovers, which is the whole point of using an autonomous agent. Overly procedural prompts constrain the subagent to a fixed path and prevent it from adjusting when the material differs from what you anticipated. This mirrors the broader agentic principle: describe the destination and the standards, and let the model reason about the route.

For example, instruct a research subagent to "produce a well-sourced overview of AI's effect on music production, with at least three independent sources and publication dates for every statistic" rather than "first call WebSearch with query X, then fetch the top result, then extract paragraph two."

Fork-based session management

Session forking lets you explore divergent approaches from a shared analysis baseline. After a coordinator or agent has done expensive upfront work (say, mapping a codebase or gathering research), you can fork the session so each branch inherits that baseline but then diverges independently, without contaminating the original or each other.

In the SDK this is forkSession (also referred to as fork_session): when resuming a session, setting it creates a new branched session id that starts from the resumed state, leaving the original session untouched. That is different from a plain resume, which continues the same session in place.

query({
  prompt: 'Now refactor using strategy A',
  options: { resume: baselineSessionId, forkSession: true }
});

The canonical use is comparing two strategies from one baseline, for example forking a shared code-analysis session into one branch that tries an incremental refactor and another that tries a full rewrite, then comparing the outcomes. Session forking is covered more deeply under task 1.7; here the key point is that it is the mechanism for divergent exploration off a common starting context.

Anti-patterns to avoid

avoid
Assuming subagents automatically inherit the coordinator's conversation or share memory across invocations.

Why it fails: Subagents run in isolated context windows. Any finding not written into the subagent's prompt is invisible to it, so the synthesis agent silently produces output based on missing information.

instead Explicitly copy the complete prior findings into each subagent's prompt. Treat every Task call as a fresh conversation that only knows what you tell it.

avoid
Spawning independent subagents one per turn (spawn, wait, spawn again) to run them 'in parallel'.

Why it fails: One Task call per response runs subagents sequentially, adding latency for work that has no dependency between the branches.

instead Emit multiple Task tool calls in a single coordinator response so the SDK runs them concurrently. Reserve sequential turns for genuinely dependent steps like synthesis after search.

avoid
Passing prior findings as one flattened prose blob without source metadata.

Why it fails: Merging claims, URLs, dates, and page numbers into sentences destroys the claim-to-source mapping, so the downstream synthesis agent cannot cite accurately and may misattribute or invent references.

instead Pass findings as structured records that separate content from metadata (claim, source_url, document, page, published) so attribution and temporal context survive the handoff.

avoid
Writing coordinator prompts as rigid step-by-step procedures (call tool X, then fetch result, then extract paragraph two).

Why it fails: Procedural scripts prevent subagents from adapting to what they actually find, which is the whole reason to delegate to an autonomous agent, and they break when the material differs from expectations.

instead Specify research goals and explicit quality criteria (coverage, minimum sources, required metadata) and let the subagent choose how to achieve them.

Worked example: Wiring a synthesis subagent in the multi-agent research system

You are building the Multi-Agent Research System (Scenario 3). A coordinator delegates to a web-search subagent, a doc-analysis subagent, and a synthesis subagent. During testing the synthesis reports read coherently but contain no citations and occasionally attribute a statistic to the wrong source. You need to fix invocation and context passing.

Step 1: confirm the coordinator can spawn. Verify allowedTools includes "Task". Without it, delegation silently never happens and the coordinator degrades into a single overloaded agent.

Step 2: fan out the independent work in parallel. Web search and document analysis do not depend on each other, so the coordinator emits both Task calls in one response:

// single assistant response -> both run concurrently
Task({ subagent: 'web-search',  prompt: 'Find sources on AI in music production...' })
Task({ subagent: 'doc-analysis', prompt: 'Extract findings from the attached industry papers...' })

Step 3: pass findings explicitly and structurally into synthesis. Because the synthesis subagent inherits nothing, the coordinator must embed both agents' outputs in the synthesis prompt as structured records, not a summary:

{
  "findings": [
    {"claim": "Streaming AI mastering grew 3x in 2024",
     "source_url": "https://example.com/report",
     "published": "2024-11-02"},
    {"claim": "70% of indie producers tried a generative tool",
     "document": "Indie Audio Survey", "page": 8,
     "published": "2025-02-15"}
  ]
}

Step 4: make the synthesis prompt goal-oriented. Instruct it to preserve every claim's source and date and to flag any claim it cannot attribute, rather than scripting exact steps. Now each cited statistic carries provenance through the handoff, misattribution disappears, and the parallel fan-out keeps latency low.

Bonus (forking): if you later want to compare two report structures from the same gathered evidence, fork the post-analysis session with forkSession: true so both drafts start from the identical research baseline without cross-contamination.

Exam tips

  • A coordinator can only spawn subagents if "Task" is in its allowedTools. No Task, no delegation.
  • Subagents run in isolated context: they do not inherit parent history and share no memory between invocations. Everything needed must be in the prompt.
  • Parallel execution = multiple Task tool calls emitted in one assistant response; one Task per turn runs sequentially.
  • An AgentDefinition is configured with a description (drives selection), a system prompt (role), and a tools restriction (scopes capability).
  • Pass prior findings as structured records that separate content from metadata (source URL, document, page, date) so attribution is preserved through synthesis.
  • forkSession (fork_session) branches a new session from a shared baseline for divergent exploration and leaves the original session unchanged; plain resume continues the same session.
Official exam objectives for 1.3
Knowledge of
  • The Task tool as the mechanism for spawning subagents, and the requirement that allowedTools must include "Task" for a coordinator to invoke subagents
  • That subagent context must be explicitly provided in the prompt — subagents do not automatically inherit parent context or share memory between invocations
  • The AgentDefinition configuration including descriptions, system prompts, and tool restrictions for each subagent type
  • Fork-based session management for exploring divergent approaches from a shared analysis baseline
Skills in
  • Including complete findings from prior agents directly in the subagent's prompt (e.g., passing web search results and document analysis outputs to the synthesis subagent)
  • Using structured data formats to separate content from metadata (source URLs, document names, page numbers) when passing context between agents to preserve attribution
  • Spawning parallel subagents by emitting multiple Task tool calls in a single coordinator response rather than across separate turns
  • Designing coordinator prompts that specify research goals and quality criteria rather than step-by-step procedural instructions, to enable subagent adaptability

Flashcards from this lesson

What must be in a coordinator's allowedTools for it to spawn subagents?

The Task tool ("Task"). It is the mechanism for spawning subagents; without it the coordinator cannot delegate.

Do subagents inherit the coordinator's conversation history?

No. Each subagent runs in an isolated context and shares no memory across invocations. Required context must be passed explicitly in its prompt.

How do you run subagents in parallel rather than sequentially?

Emit multiple Task tool calls in a single coordinator response. One Task call per turn runs them sequentially.

What three fields define an AgentDefinition?

A description (used to select the subagent), a system prompt (its role and behavior), and a tools restriction (which tools it may call). An optional model can also be set.

What does fork_session / forkSession do?

It branches a new session from a shared baseline to explore divergent approaches, leaving the original session untouched. Plain resume continues the same session in place.

Should coordinator prompts be procedural or goal-oriented?

Goal-oriented: specify research goals and quality criteria, not step-by-step actions, so subagents can adapt to what they discover.

Why pass findings between agents as structured records instead of prose?

Separating content from metadata (source URL, document, page, date) preserves claim-to-source attribution so the synthesis agent can cite accurately and avoid misattribution.

Study all flashcards with spaced repetition