A single agent with a long prompt and many tools is the default design, and usually the right one. It starts to strain when one prompt has to describe several jobs: a researcher, a writer and a reviewer each need different instructions and tools, and a model reading all of them at once attends to the wrong ones. Splitting the work across agents can fix that. It also adds messages, tokens, and new ways to fail. This module covers the three ways to divide work between agents, what each agent gets to see in each, how agents run by different teams reach each other over a network, and what goes wrong in systems of agents.
Notebooks
Notebook 9a: Workflows, agents as tools, and handoffs splits one help-desk ticket across agents in a sequential, a parallel and a loop workflow, through a manager that calls agents as tools, and through a triage desk that hands the conversation to a specialist, then stages two classic failures. Notebook 9b: Agents over the network with A2A serves an agent on 127.0.0.1 behind an agent card and JSON-RPC, calls it by hand, and gives a local planner two remote agents as tools.
Why use more than one agent
Definition 9.1 (Multi-agent system).A multi-agent system is a set of agents, each with its own instructions, tools and context, that work on a shared task. Its design fixes three things: orchestration (who decides which agent runs next), communication (what each agent is told) and coordination (how interdependent work and shared state are managed).
Hur and Song motivate multi-agent systems (Definition 9.1) with a blog-writing assistant that has to research, write code, draft and review. In one prompt, the review rules distract the writer and a dozen tools confuse the choice of the next call. Four specialists each get a short prompt and only the tools they need. CS329Z’s lecture on multi-agent systems lists the benefits that come from such a split: specialisation (instructions, tools and even models tailored to one job), focused context (each agent sees only what its job needs), parallel execution of independent subtasks, and broader exploration of several approaches at once. It lists the costs just as clearly: coordination overhead in tokens and time, information loss when a handoff omits something, conflicting actions, error propagation from one agent to the next, and engineering complexity.
Remark 9.1 (Start from one agent).Build a strong single-agent baseline first and measure it. Add an agent when it removes a bottleneck you have measured (a context that is too long, subtasks that could run at the same time, a review step that catches real errors), and keep it only if the gain outweighs what coordination costs.
The rest of the module is about doing that split well when the baseline test (Remark 9.1) says it is worth it.
Three ways to divide the work
Hur and Song distinguish three collaboration patterns. They differ in who chooses the next agent and in what the next agent sees.
| who decides what runs next | what the other agent sees | who answers the user | |
|---|---|---|---|
| workflow | your code | whatever your code passes on | the last agent in the chain |
| agent as tool | the calling agent’s model | only the request it was given | the caller |
| handoff | the current agent’s model | the whole conversation so far | the agent handed to |
A workflow is the multi-agent version of the workflow from Module 1: code fixes the
order. Three building blocks cover most needs. A sequential workflow runs agents one after
another in a shared context, so the writer reads the researcher’s notes. A parallel
workflow runs independent agents at the same time and merges their outputs; in notebook 9a
three checkers that take 0.30, 0.10 and 0.20 seconds finish together in about 0.30 seconds,
not 0.60. A loop repeats agents until a condition holds: a drafter and a reviewer
alternate until the reviewer approves, which is the evaluator-optimizer pattern from
CS329Z’s lecture on design patterns. Every loop needs max_iterations, because a reviewer
that is never satisfied would otherwise run until the budget is gone.
Definition 9.2 (Agent as tool).An agent as tool wraps an agent behind a tool interface: one string argument (the request), the sub-agent’s final answer as the result. The sub-agent starts from an empty context containing only the request, and the caller sees only its answer.
Definition 9.3 (Handoff).A handoff (Hur and Song call it a transfer) is a tool,
transfer_to_agent, whose effect is to make another agent the active one. The run continues with that agent on the same context, so it sees everything said so far, and the user’s next turn goes straight to it.
Use an agent as a tool (Definition 9.2) when one agent should integrate the specialists’ contributions and own the final reply: an orchestrator with workers. Use a handoff (Definition 9.3) when the specialist should take over the conversation itself, as when a triage desk passes a billing question to billing. In notebook 9a the follow-up “When will I see the money?” goes to the billing agent directly, with no triage step, and billing answers without asking which refund, because it can read its own earlier turn.
What each agent sees
The choice between the patterns is mostly a choice about context, and notebook 9a measures it. The same researcher-then-writer job, run as a sequential workflow and then as a manager calling both as tools, spends its input tokens like this:
| agent | shared context (sequential) | isolated (agent as tool) |
|---|---|---|
| researcher | 667 | 707 |
| writer | 395 | 146 |
| manager | 0 | 1,215 |
With isolation the writer reads about a third of the tokens: its request and the notes, not the researcher’s raw tool results. The manager pays for that: it reads the ticket, the notes and the draft, and its three calls cost more than the whole sequential run. Isolation keeps each worker focused; it is not automatically cheaper.
The sub-agent’s fresh context is one line in AgentTool.execute:
async def execute(self, context, **kwargs):
request = kwargs.get("request", str(kwargs))
result = await self.agent.run(request) # a new, empty context: only the request
self.runs.append(result)
if result.status != "complete":
raise SubAgentFailed(f"{self.name} stopped with status {result.status!r}")
return result.outputThat line is also the interface’s weakness. In the notebook’s staged failure, a careless manager asks the researcher to “Look up the account for this ticket” without including the ticket. The researcher, doing its job correctly, reports that there is no customer id and no matching article. Nothing crashed; the information simply never crossed the boundary. With agents as tools the request is the interface, so the tool description should demand every detail (“the ticket text, including the customer id”), or the tool should take structured input that a model cannot leave half empty.
Handoffs have the opposite failure. Two agents that each believe the other should answer
can pass the conversation back and forth indefinitely. A per-agent step budget does not
catch it, because each agent stops after a single step; the limit has to count handoffs
across the run. In the notebook, max_handoffs=4 stops the ping-pong at the fifth transfer
and returns the route, so the loop is visible in the result rather than in the bill.
Agents across the network: A2A
Everything so far ran in one Python process. An agent built by another team runs elsewhere, with its own model, tools and memory that you cannot see. The Agent2Agent protocol (A2A), introduced by Google in 2025 and now developed under the Linux Foundation, standardises how such agents find and call each other. Where MCP (Module 3) connects an agent to tools, which have schemas and no model behind them, A2A connects an agent to another agent, which takes a message in plain language and decides for itself how to answer.
Definition 9.4 (Agent card).An agent card is a JSON document an A2A server publishes at
/.well-known/agent-card.json. It gives the agent’s name and description, the URL and transport to send work to, its optional capabilities (streaming, push notifications), the media types it accepts and returns, and a list of skills, each with a description for a calling model to choose by.
After reading the card (Definition 9.4), the client posts JSON-RPC 2.0 requests to its URL.
message/send carries one Message (a role, an id and a list of parts) and returns a
Task: an id, a contextId for the conversation, a status such as completed, and the
output as artifacts. A follow-up that sends the same contextId continues the remote
conversation; without it, the server starts a new one. In notebook 9b, “And the same
amount in GBP?” returns GBP 94.36 with the context id, and a request for the amount without
it.
The notebook’s server and client implement a faithful but deliberately small subset of A2A
v0.3: the card, message/send, tasks/get and the standard error codes, in a few hundred
lines of standard-library Python and httpx, so every byte on the wire is visible. The
specification has since reached version 1.0, which renames the JSON-RPC methods to match
gRPC (SendMessage, GetTask); the ideas below carry over unchanged. The subset
leaves out streaming over server-sent events, push notifications for long tasks, the
input-required and auth-required states in which a remote agent pauses to ask
something, file and data parts, the other transports, and every security scheme. For real
services use the official SDK. A remote agent wrapped as a tool looks to the local model
like any other tool: fx_desk, with one string argument and the card’s description.
Two consequences follow from the remote agent being opaque. Its costs are invisible: the remote model calls are billed to whoever runs the server, and the Task has no standard field for usage, so budgets across organisations have to be agreed outside the protocol. And its answer is untrusted input. A compromised remote agent can put instructions into its reply, which the caller’s model then reads; treat remote answers as data, as you would any tool result (Module 12).
Why systems of agents fail
Cemri et al. (2025) collected failed runs from several open-source multi-agent frameworks and sorted the failures into a taxonomy with three groups:
| group | examples | in notebook 9a |
|---|---|---|
| specification and system design | ignored role or task constraints, steps repeated, no sense of when to stop | the handoff ping-pong |
| inter-agent misalignment | information withheld, another agent’s input ignored, a conversation reset | the careless manager |
| task verification | stopping too early, missing or incorrect checks of the result | what the reviewer loop and its fixed checker guard against |
Their main finding is that many failures come from the design of the system rather than from the model alone: better prompts and stronger models help, but not enough without clear roles, explicit hand-over formats and real verification. CS329Z adds failures that appear as systems grow, such as agents converging on the same idea or settling conflicting goals by force. The practical defences are the ones this module has used: limits on loops and handoffs, requests that carry everything the receiver needs, checks that do not depend on the model’s own judgement, and traces that show who saw what (Module 10).
Try this
- In notebook 9a, give the researcher tool an
input_schemawithticketandcustomer_idfields and re-run the careless manager. How does the tool definition change, and why would that help a real model? - Add a fourth checker that takes 0.5 seconds to the parallel panel. Predict the elapsed time before you run it.
- Set
max_handoffs=50on the ping-pong pair and count the model calls the route costs before it stops. Which failure group of Cemri et al. is this? - In notebook 9b, send a request with the old method name
tasks/sendthat the book’s text uses. Which error code comes back, and what would a client need to support both protocol versions? - Wrap the FX desk with
RemoteAgent(..., keep_context=True)and ask the planner two related questions. Where is the conversation stored, and who pays for its growing context?
Readings
- Hur and Song, Build an AI Agent (From Scratch), Manning 2026, chapter 9.
- Stanford CS329Z, Engineering AI Agents, Lecture 8: Multi-agent systems (slides), and Lecture 6: Agent design patterns and scaffolds (slides).
- Cemri et al., Why do multi-agent LLM systems fail?, 2025.
- Wu et al., AutoGen: enabling next-gen LLM applications via multi-agent conversation, 2023.
- Hong et al., MetaGPT: meta programming for a multi-agent collaborative framework, ICLR 2024.
- Fourney et al., Magentic-One: a generalist multi-agent system for solving complex tasks, 2024.
- Agent2Agent (A2A) protocol specification.