CONCEPT The coordinator's three jobs
In the coordinator/sub-agent pattern, one central agent owns the top-level goal and does three things: route (decide which specialist should handle a piece of work), delegate (hand that specialist an explicit, self-contained task), and merge (aggregate and synthesize the specialists' outputs into one answer). The specialists never talk to each other or to the user — everything flows through the coordinator.
| Job | What the coordinator does | Detail in… |
|---|---|---|
| Route | Reads the goal and picks which specialist(s) apply | 4.2 (router pattern) |
| Delegate | Sends each specialist an explicit task with the state it needs | 4.4, 4.5 |
| Merge | Aggregates/synthesizes outputs, resolves conflicts | 4.7 |
CONCEPT Sub-agents-as-tools
A clean way to build a coordinator: expose each specialist to the coordinator as a tool. From the coordinator's point of view, "ask the research specialist" is just another tool call — the model decides when and with what input to invoke it. Under the hood, that tool spins up a context-isolated sub-agent (its own model loop and context window; see 4.4), runs it, and returns the result as the tool_result. This keeps the coordinator's own loop simple: it reasons, calls "tools" (some of which are whole agents), and integrates results.
DIAGRAM Coordinator flow
(owns the goal)"] C -->|route + delegate
explicit task| S1["🔵 Research specialist
own context"] C -->|route + delegate
explicit task| S2["🔵 Analysis specialist
own context"] S1 -->|result| C S2 -->|result| C C -->|merge + synthesize| A(["✔ Final answer"]) classDef p fill:#e2d4f0,stroke:#764ba2,color:#3d1a5b; classDef b fill:#d1ecf1,stroke:#17a2b8,color:#0c5460; classDef g fill:#d4edda,stroke:#28a745,color:#155724; class C p; class S1 b; class S2 b; class A g;
CODE Coordinator sketch (delegate → collect → merge)
Specialists exposed as tools. The coordinator's loop lets the model decide which specialist to call; each call runs a context-isolated sub-agent and returns its output as a tool_result.
# Each specialist = a context-isolated sub-agent with its OWN messages list. def run_specialist(system, task, model="claude-sonnet-4-6"): # Fresh context: the sub-agent does NOT see the coordinator's history. r = client.messages.create( model=model, max_tokens=2048, system=system, messages=[{"role": "user", "content": task}], # explicit, self-contained ) return "".join(b.text for b in r.content if b.type == "text") # Specialists surfaced to the coordinator AS TOOLS (sub-agents-as-tools). TOOLS = [ {"name": "research", "description": "Gather facts on a topic.", "input_schema": {"type": "object", "properties": {"topic": {"type": "string"}}, "required": ["topic"]}}, {"name": "analyze", "description": "Analyze given findings.", "input_schema": {"type": "object", "properties": {"findings": {"type": "string"}}, "required": ["findings"]}}, ] def dispatch(name, args): if name == "research": return run_specialist("You are a research specialist.", f"Research: {args['topic']}") if name == "analyze": return run_specialist("You are an analysis specialist.", f"Analyze these findings:\n{args['findings']}") # Coordinator loop: the MODEL routes by choosing which specialist-tool to call. messages = [{"role": "user", "content": goal}] while True: resp = client.messages.create(model="claude-opus-4-8", max_tokens=4096, system="You are a coordinator. Delegate to specialists, then merge.", tools=TOOLS, messages=messages) messages.append({"role": "assistant", "content": resp.content}) if resp.stop_reason != "tool_use": break # coordinator produced the merged answer results = [] for block in resp.content: if block.type == "tool_use": out = dispatch(block.name, block.input) # run the specialist sub-agent results.append({"type": "tool_result", "tool_use_id": block.id, "content": out}) messages.append({"role": "user", "content": results}) # feed results back; coordinator merges
EXAM TRAPS
PRACTICE
Q1 · Why expose specialists as tools rather than hand-writing routing logic?
It reuses the coordinator's existing tool-use loop and lets the model route dynamically, picking the right specialist (and its input) based on the goal — no brittle hand-coded dispatch tree.
Q2 · The analysis specialist needs the research findings. How does it get them?
The coordinator passes them explicitly — here, as the findings tool input.
The specialist is context-isolated and can't see the research turn otherwise (4.5).
Q3 · Which of the coordinator's three jobs does the final loop iteration perform?
Merge. After the last tool_result is fed back, the coordinator synthesizes the specialists' outputs into one answer and stops (stop_reason ≠ tool_use). Conflict resolution happens here too (4.7).