Passing Context to Subagents: Nothing Is Inherited, So Put Findings, Goal and Criteria in the Prompt
A synthesis subagent asked to write the report from the research has nothing to work from: it never saw the coordinator's chat. handoff.py builds the prompt it needs from findings.json: the goal, three quality criteria and three findings, each with its document and page.
What you will learn
- Explain why a subagent sees only the prompt text the coordinator sends
- Build a handoff prompt with complete findings, a goal and quality criteria instead of step-by-step orders
- Keep content apart from metadata so every claim keeps its source and page
- Describe a subagent with AgentDefinition (description, prompt, tools) and spot the "findings above" bug
Before you start
- Coordinator and subagents: decompose, delegate, check coverage
- The Claude Agent SDK: query and ClaudeAgentOptions
The research is done. The coordinator has three findings about city bike lanes, and it asks the synthesis subagent to write the report. The subagent can only ask back: which research?
A subagent starts with an empty head. It doesn't inherit the coordinator's conversation, and it doesn't share its memory. Whatever it must know has to be written in its prompt. This article shows what that prompt needs and how to build it, after the coordinator has done its research.
Two chats, no shared memory
On one side, the coordinator's chat: the user's request, web search results, two analysed papers, three findings with sources. On the other side, the subagent's chat. It's empty.
The coordinator makes a Task call that says write the report. From the subagent's side there's nothing to write about. It never saw the coordinator's chat. That separate, clean context is the whole point of a subagent (see context isolation through subagents), and it's also why the handoff has to be complete.
Think of hiring a new contractor. You remember every meeting and email; the contractor remembers nothing about your job. So you write a briefing pack: the goal, the facts, and where each fact came from. The contractor does the job from the pack alone. Your memories don't travel. In an agent system, the prompt is the briefing pack.
Findings, goal, criteria
So what goes into that prompt? Three parts.
- The complete findings. Every claim, every evidence excerpt, and its source. All of them, not a summary of them.
- The goal. What the report is for, and who will read it.
- Quality criteria. Cite every claim. Flag disagreements.
What to leave out: step-by-step orders like "Step 1: open finding 1. Step 2: write one line." A script breaks when the data changes. A goal and a quality bar let the subagent adapt.
Keep content apart from metadata
Here is the project's findings.json. In each finding the content (the claim and its evidence) sits in one object, the metadata (URL, document, page) in another:
[
{"content": {"claim": "Protected lanes raised weekday bike trips",
"evidence": "Counters on Main St showed more riders"},
"meta": {"source_url": "https://example.org/city-cycling",
"document": "City Cycling Report", "page": 12}},
{"content": {"claim": "Riders felt safer on separated lanes",
"evidence": "Most survey answers rated them safe"},
"meta": {"source_url": "https://example.org/rider-survey",
"document": "Rider Survey", "page": 4}},
{"content": {"claim": "Shop sales on lane streets stayed steady",
"evidence": "Monthly sales stayed in the usual range"},
"meta": {"source_url": "https://example.org/shop-study",
"document": "Shop Study", "page": 7}}
]
Because they are kept apart, the synthesis subagent can write the claim and attach its source: Protected lanes raised weekday bike trips [City Cycling Report, p.12]. Paste all the findings into one paragraph ("Protected lanes raised trips. Riders felt safer.") and the link is gone. Who said it? Nobody can tell. Metadata travels with each claim, so attribution survives. The findings in the file are made-up sample data.
handoff.py: build the briefing pack
The handoff itself is plain Python, 26 lines, no API key and no packages:
import json
GOAL = "Summarize what the findings say about city bike lanes."
CRITERIA = [
"Use only the findings below.",
"Cite the document and page after each claim.",
"Say so if two findings disagree.",
]
def build_prompt(findings):
lines = ["GOAL: " + GOAL, "QUALITY CRITERIA:"]
lines += ["- " + c for c in CRITERIA]
lines.append("FINDINGS:")
for i, f in enumerate(findings, 1):
c, m = f["content"], f["meta"]
lines.append(f"{i}. {c['claim']}")
lines.append(f" evidence: {c['evidence']}")
lines.append(f" source: {m['document']}, page {m['page']}")
lines.append(f" url: {m['source_url']}")
return "\n".join(lines)
if __name__ == "__main__":
with open("findings.json") as fh:
print(build_prompt(json.load(fh)))
GOAL and CRITERIA say what good looks like, not which steps to take. Inside the loop, c and m read content and meta separately, two reads, never mixed. And the source and page go on the lines right under each claim, so no claim travels alone.
Run python handoff.py. There's no model in this file, so the printout is the prompt itself, exactly the text the subagent would receive:
GOAL: Summarize what the findings say about city bike lanes.
QUALITY CRITERIA:
- Use only the findings below.
- Cite the document and page after each claim.
- Say so if two findings disagree.
FINDINGS:
1. Protected lanes raised weekday bike trips
evidence: Counters on Main St showed more riders
source: City Cycling Report, page 12
url: https://example.org/city-cycling
2. Riders felt safer on separated lanes
evidence: Most survey answers rated them safe
source: Rider Survey, page 4
url: https://example.org/rider-survey
3. Shop sales on lane streets stayed steady
evidence: Monthly sales stayed in the usual range
source: Shop Study, page 7
url: https://example.org/shop-study
Goal and criteria first, then each finding with its claim, evidence, source, page and link. This text is the whole briefing pack. It's all the subagent gets.
agents.py: describing the subagent
In the Claude Agent SDK, the subagent itself is described with an AgentDefinition. The project shows this file but doesn't run it:
from claude_agent_sdk import AgentDefinition
from claude_agent_sdk import ClaudeAgentOptions
synthesizer = AgentDefinition(
description="Use after research is done, "
"to write a cited summary.",
prompt="You write short cited summaries. "
"Use only the findings in the task. "
"Never invent a source.",
tools=["Read"],
)
options = ClaudeAgentOptions(
allowed_tools=["Agent"],
agents={"synthesizer": synthesizer},
)
descriptiontells Claude when to pick this subagent.promptis its system prompt: its job and its limits. It's fixed, so the findings for this particular job still have to come in the Task call's prompt, the texthandoff.pybuilds.toolsrestricts what it may use. Here onlyRead, so it can look at files and nothing else.allowed_toolson the coordinator lists the tool that spawns subagents. Without it, the coordinator can't delegate at all.
A naming note: this file writes "Agent", the name in the current docs. The exam guide calls the same tool Task, which is what the research team file uses. Check the docs for your SDK version. For configs that look right and still fail, see fixing Agent SDK configs.
One more idea from the same exam task: fork_session. After one shared analysis you can fork the session, and each fork starts from the same baseline and continues on its own. Fork A tries tracked lanes, fork B tries shared streets, and neither disturbs the other. Sessions get their own lesson in Resume, Fork or Start Fresh, so we'll leave it there.
Break it: "the findings above"
The bug: the coordinator's prompt says Summarize the findings above. Above what? This is a fresh subagent. There is no above.
It sees no findings anywhere, and the risk is worse than an error: a confident summary with invented facts and sources, and nothing in it can be checked. The fix is to paste the findings into the prompt, all three, with their sources, which is what build_prompt does. Words like above, earlier and the research so far point at a chat the subagent never saw.
How this shows up in a question
A synthesis subagent writes a vague, uncited report, and its prompt turns out to say "write the report from the research so far". A larger model, more tools, or telling it to ask the search subagent won't help: the model can only use what is in its prompt, and subagents don't share memory. The fix is to put the full findings, with sources, in that prompt. Ask one thing: is the data inside the subagent's own prompt?
Common mistakes
- Pointing at the chat. "Above", "earlier", "so far" mean nothing to a subagent.
- Sending a summary of the findings. Send them complete, with evidence, or the subagent can't cite or weigh them.
- Flattening metadata into prose. Once document and page are mixed into a paragraph, attribution is lost.
- Scripting the steps. Give a goal and quality criteria; let the subagent decide how.
- Forgetting the spawning tool. No Task (or Agent) in
allowed_tools, no subagent.
Quick recap
| Put in the prompt | Why |
|---|---|
| Complete findings (claim + evidence) | The subagent has no other copy |
| Source, document and page next to each claim | Citations survive the handoff |
| The goal | It knows what the report is for |
| Quality criteria | It knows what good looks like without step-by-step orders |
The project files for this lesson are in the community, free to join.
Try it yourself
Comment out the two lines in build_prompt that add source and url, run handoff.py again, and read the printout as if you were the subagent: which claim can you still cite? Then put the lines back, add a fourth finding to findings.json that disagrees with the first, and check that the third quality criterion gives the subagent a reason to say so.
Related course on Udemy
Claude Certified Architect - Foundations (CCAR-F) Exam Prep
Agentic loops, tools, MCP, Claude Code, prompts, structured output and context.View on Udemy ↗: Claude Certified Architect - Foundations (CCAR-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
