Skip to content
Domain 1Task 1.3

Subagent Invocation and Context Passing

Learn this interactively

What You Need to Know

A coordinator is the agent that runs a multi-agent task and gives parts of it to subagents. Invocation is how the coordinator starts a subagent. Context passing is how the coordinator gives that subagent the information it needs. Task Statement 1.3 covers these mechanics. If 1.2 taught you the architecture, 1.3 teaches you how the parts connect.

This lesson uses one made-up example throughout: a landscaping firm that uses a multi-agent system to draft planting proposals for clients. Its coordinator spawns three subagents. A web search subagent finds plant and supplier information online and returns results with URLs and titles. A document analysis subagent reads the firm's supplier catalogues and returns analysis with page references. A synthesis subagent writes the proposal from the results of both, and every claim in it should name its source.

The Task Tool

The Task tool is how a coordinator spawns subagents. It is the API mechanism that makes multi-agent orchestration work in the Claude Agent SDK, so it is more than a naming convention. Current state (checked 6 October 2026): Claude Code renamed it Agent in v2.1.63. The name Task still works as an alias, and the Agent SDK emits Agent in tool-use blocks.

The coordinator's allowedTools must include "Task" (or "Agent", its name in Claude Code since v2.1.63). This is a yes-or-no requirement. With neither name on the list, the coordinator has no way to invoke subagents at all. The firm's coordinator could have three well-defined subagents and invoke none of them.

Key Concept

Without "Task" (or "Agent") in its allowedTools, the coordinator cannot invoke any subagent, however the subagents are defined.

An AgentDefinition defines each subagent. It specifies three things:

  1. Description: what the subagent does. The coordinator reads it to decide when to invoke the subagent.
  2. System prompt: the instructions the subagent follows.
  3. Tool restrictions: which tools the subagent can access, scoped to its role.

At the firm, the web search subagent's description says it finds plant and supplier information online. Its tools are limited to search, which is its whole role.

Context Passing

Subagents have isolated context, the principle from 1.2. A subagent receives only what the coordinator writes into the subagent's prompt. It does not see the coordinator's history or another subagent's output. Most multi-agent systems fail at this point. Three rules follow.

Rule 1: Include complete findings from prior agents. A synthesis subagent cannot find earlier results, because its prompt is its only input. If it needs web search results and document analysis output, the coordinator must pass both in full. At the firm, the coordinator puts both in the synthesis subagent's prompt.

Rule 2: Use structured data that separates content from metadata. Content is the claim, the fact or the analysis. Metadata says where the content came from: source URL, document name, page number. A downstream agent can attribute a claim to a source only if the coordinator passes that metadata with the claim. When a coordinator compresses findings for the next agent and removes the link between each claim and its source, the attribution is lost.

Rule 3: Specify goals, not procedures. A coordinator prompt should tell a subagent what to achieve and which quality criteria to meet, not give step-by-step instructions. A fixed procedure gives the subagent no way to adjust its approach when it meets something unexpected. A goal lets it adjust its approach. The firm's coordinator asks the web search subagent for suppliers on the planting list, each with a URL. The coordinator names no sites, so the subagent can search other sites when one site has nothing useful.

Structured Metadata Format

A practical format keeps content and metadata in separate fields, as in this example:

json
{
  "findings": [
    {
      "claim": "Solar panel efficiency has increased 25% in the last decade",
      "source_url": "https://example.com/solar-report",
      "document_name": "Annual Solar Industry Report 2024",
      "page_number": 14,
      "confidence": "high",
      "retrieved_by": "web_search_agent"
    }
  ]
}

Each finding contains its source attribution as metadata. A synthesis subagent that receives findings in this format has everything it needs to produce a properly cited report.

When Attribution Fails

At the firm, both research subagents return well-sourced work: URLs and titles from web search, page references from the catalogue analysis. The coordinator passes the content of both to the synthesis subagent but removes the metadata: no source URLs, document names or page numbers. The synthesis subagent writes an excellent proposal with no source attribution.

A change to the synthesis subagent's prompt does not fix this problem, because the subagent cannot cite sources that it does not have. The coordinator must pass structured metadata with the content, and keep the source URL, document name and page number for every finding.

Parallel vs Sequential Spawning

When a coordinator needs several subagents for independent tasks, it should emit multiple Task tool calls in a single response. Sequential spawning means one subagent per coordinator turn. The second subagent cannot start until the first has returned and the coordinator takes another turn. When the tasks are independent, that wait adds latency with no benefit. The firm's web search and catalogue analysis tasks do not depend on each other, so the coordinator spawns both subagents in one response.

Key Concept

Spawn independent subagents in parallel by emitting multiple Task tool calls in a single coordinator response. Parallel spawning reduces latency compared to sequential invocation across separate turns.

fork_session

fork_session creates independent branches from a shared analysis baseline. After an initial analysis, such as reading a codebase or understanding a problem, a coordinator can fork the session to explore divergent approaches. After the branching point, each fork works independently. Neither sees the other's results, and changes in one do not affect the other. A coordinator might fork after analysing a codebase to compare two testing strategies. The firm's coordinator forks after analysing a client's site survey to compare two planting plans.

--resume and fork_session are both Claude Code session controls. --resume is a CLI flag, with a matching resume option in the Agent SDK. fork_session is the SDK option (forkSession in TypeScript). It is also on the CLI as --fork-session, next to --resume.

fork_session is not the same as --resume. Resume continues a specific named session. Fork creates a new independent branch. Use fork to explore divergent approaches from a shared starting point. Use resume to continue the same line of investigation, as the firm does to continue one proposal.

In the exam

Exam guide v1.0 uses the name Task tool, so answer "Task tool" even where current code shows Agent. Exam guide v1.0 states the allowedTools rule as above, and that is the right answer.

One question: a synthesis agent's report has unsourced claims, while the web search and document analysis subagents work correctly. The coordinator passed content without structured metadata, so the synthesis agent had no source information to include.

Exam Trap

When a synthesis agent produces unsourced claims, the exam expects you to identify the context passing failure: missing structured metadata. Do not blame the synthesis agent's prompt or propose giving it direct tool access.

The exam tests whether you are aware of latency. For independent subagent tasks, the correct answer involves parallel spawning. Options that mention "in a single response" or "simultaneously" signal parallel spawning.

The exam also tests the difference between fork and resume. Exam guide v1.0 lists --resume and fork_session as two session controls, and that is how the exam frames them. Answer that way: resume to continue a session, fork to branch from it.

Where Current Docs Differ

Current state

Current state (checked 6 October 2026): the Agent SDK docs describe allowedTools as an auto-approve list. Omitting Agent from that list does not remove the tool. Instead, every spawn goes through the permission callback. In an unattended run, that callback denies the spawn. The outcome on the exam is the same, but the mechanism in production is different.

Current state

Current state (checked 6 October 2026): in the Agent SDK (sessions guide), fork is a modifier on resume, not an alternative to it. You pass both: ClaudeAgentOptions(resume=session_id, fork_session=True). resume names the session to start from, and fork_session says to branch from it instead of appending to it. Omit fork_session and the same call appends to the original session. The CLI pairs them the same way: --fork-session has an effect only together with --resume or --continue. So the distinction is append versus branch, not one flag versus the other.

Exam Traps

Exam Trap

Assuming subagents automatically have access to the coordinator's conversation history or other subagents' outputs

Subagents have isolated context. Every piece of information they need must be explicitly included in their prompt by the coordinator. There is no automatic context inheritance.

Exam Trap

Blaming the synthesis agent's prompt when claims in its report lose their source citations

The synthesis agent cannot cite a source it was not given. If the coordinator passes findings without source URLs, document names and page numbers, attribution is lost. Have the coordinator pass findings as structured data that keeps that metadata separate from the content.

Exam Trap

Proposing sequential subagent invocation for tasks that can run independently

Sequential invocation introduces unnecessary latency. Independent tasks should be spawned in parallel using multiple Task tool calls in a single coordinator response.

Exam Trap

Writing a subagent's prompt as an exact step-by-step procedure so it cannot deviate from the plan

A fixed procedure breaks when the input differs from what its author expected, and the subagent cannot adapt. State the goal and the quality criteria for a good result, then let the subagent choose how to get there.

Practice Scenario

A synthesis agent produces a report where several claims have no source attribution. The synthesis agent's prompt and tool set are unchanged from when its reports were fully cited. The web search and document analysis subagents are working correctly and returning well-sourced results in the same format they always have. What is the most likely root cause?

Build Exercise

Build Exercise

Implement Context Passing with Structured Metadata

Difficulty
50 minutes

What you'll learn

  • Why the coordinator allowedTools must include Task (or Agent, its name since Claude Code v2.1.63) to spawn subagents
  • How to design structured metadata that separates content from source attribution
  • Why context passing failures cause attribution errors in downstream agents
  • How to spawn independent subagents in parallel for reduced latency
  • The difference between fork_session and parallel Task tool invocation
  1. Create a coordinator agent with Task (or Agent) in its allowedTools

    Why: Task is a strict requirement for subagent spawning. Current state (checked 6 October 2026): Claude Code v2.1.63 renamed it Agent, and Task still works as an alias. Without it in allowedTools, the coordinator cannot invoke any subagent. The exam tests this as a binary requirement — it is not optional or configurable at runtime.

    You should see: A query() call whose options include allowedTools explicitly containing Agent (or Task) alongside any other tools the coordinator needs directly, plus the subagent definitions under options.agents.

  2. Define two subagents: a web search agent that returns results with source URLs and titles, and a document analysis agent that returns analysis with page references

    Why: Each subagent needs scoped tool access matching its role. The exam tests whether you define subagents with proper AgentDefinition fields: description, system prompt, and tool restrictions.

    You should see: Two AgentDefinition objects, each with a description, system prompt, and restricted tool set. The web search agent has search tools only; the document analysis agent has file reading tools only.

  3. Design a structured output format that separates content from metadata: each finding includes claim, source_url, document_name, page_number, and confidence

    Why: The exam specifically tests the attribution failure pattern: when a synthesis agent produces unsourced claims, the root cause is that the coordinator passed content without structured metadata. Separating content from metadata is the fix.

    You should see: A TypeScript interface or JSON schema defining the Finding type with both content fields (claim, analysis) and metadata fields (source_url, document_name, page_number, confidence, retrieved_by).

  4. Pass complete structured results from both subagents to a synthesis subagent, preserving all metadata

    Why: This is the critical step the exam targets. Stripping metadata before passing to the synthesis agent is the root cause of attribution failures. The coordinator must pass the full structured output, not just the claim text.

    You should see: The coordinator passes the complete findings array (with all metadata intact) to the synthesis agent prompt. No metadata fields are stripped or summarised away.

  5. Verify that the synthesis agent can attribute every claim in its output to a specific source with URL and page number

    Why: This verification step confirms the context passing worked. If any claim lacks attribution, trace back to whether the metadata was actually passed — do not blame the synthesis agent prompt.

    You should see: A synthesis report where every factual claim includes a citation with source URL and page number. No claims without attribution.

  6. Refactor the coordinator to spawn both research subagents in parallel using multiple Task tool calls in a single response

    Why: The exam tests latency awareness. Sequential spawning of independent subagents wastes time. Parallel spawning via multiple Task tool calls in a single coordinator response is the correct pattern for independent tasks.

    You should see: Both the web search and document analysis subagents invoked simultaneously via parallel Task tool calls, with the coordinator waiting for both to complete before proceeding to synthesis.

Sources