Courses / Agentic AI / Module 7
Module 7: Multi-agent patterns: supervisor, hierarchical, swarm and handoffs
12 h · theory 4 · hands-on 5 · project 2 · revision 1
You will be able to
- Build a supervisor that routes to specialist agents
- Use handoffs and shared state safely
- Compare LangGraph, OpenAI Agents SDK and Pydantic AI
- Know when multi-agent is worse than one agent
Capstone increment: Supervisor with log, metrics and runbook agents.
Job-description skills: Multi-agent orchestration, Agent frameworks · Lab tools: langgraph, openai-agents, pydantic-ai
1. When more than one agent helps
Multiple agents earn their cost in three situations: work that can run in parallel (several lines of research at once), parts that need different tools or permissions (a read-only investigator and an approval-gated fixer), and contexts that would overflow a single agent. Anthropic reported that its multi-agent research system beat a single agent by a wide margin on research tasks, while using about 15 times the tokens of a chat.
The common shape is a supervisor that routes work to specialists with narrow tools and gathers their findings in shared state.
2. Supervisor, hierarchy and handoffs
A supervisor (or orchestrator) decides which specialist works next and when the task is done. Hierarchies nest supervisors for large problems. Handoffs, as in the OpenAI Agents SDK, transfer the conversation from one agent to another; agents-as-tools keep one agent in charge and call others like functions.
Decide how agents share information: a shared state object (explicit, inspectable), or messages passed between them (flexible, easy to lose context in). Structured outputs from specialists (a claim, evidence, confidence) make the supervisor’s job and your evals much easier.
3. Reliability and cost
Every step can fail, and failures compound: twenty steps at 95% each finish about a third of the time. Splitting work across agents adds handoffs, each of which can drop context, and every agent pays for its own prompt and tools. Multi-agent designs win only when specialists are genuinely more reliable at their narrower job or when parallelism matters. Use the model below to explore the trade-off.
| Design | Task success | Tokens | Time |
|---|---|---|---|
| One agent | 60% | 97,500 | 60 s |
| Supervisor + 4 specialists | 56% | 1,34,000 | 72 s |
Success = (per-step success)^steps × (handoff success)^handoffs. Real numbers come from your own evals, not from this model.
Guided experiments
- Leave the specialist gain at 0. Can any number of handoffs make the multi-agent design more reliable? Why do handoffs only ever subtract?
- Set 90% per step and 20 steps. What is one agent’s chance of finishing? This compounding is why long agent runs feel unreliable.
- Give specialists a gain of +3 points and 3 parallel workers. When does the supervisor design win on success and on time? Does it ever win on tokens?
- Drop handoff context to 90%. How much specialist gain do you now need to break even? What would you put in a handoff to keep it high?
4. Frameworks compared
LangGraph models agents and supervisors as explicit graphs with shared state, checkpoints and interrupts: the most control. The OpenAI Agents SDK offers agents, handoffs, guardrails and built-in tracing with little code. Pydantic AI gives typed agents with dependency injection and validated outputs. CrewAI organises role-based crews with tasks.
Choose by how much control you need over flow and state, how you will test it, and which tracing and deployment story fits your stack. Build the same small supervisor in two frameworks before committing.
5. Handoffs that keep context
Most multi-agent failures are context failures: the next agent doesn’t know what was found, what was ruled out or what it must not do. Make the brief a schema: goal, findings so far, constraints, and the exact format to return.
Trace across agents with one trace id per task so you can see who did what. Then evaluate the multi-agent design against a single agent on the same scenarios; keep it only if it wins on what you care about.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 7.1: Supervisor in LangGraph
Build a supervisor with log, metrics and runbook specialists, each with its own tools, shared state for findings and a step budget.
Expected: Traces showing routing decisions and each specialist’s structured finding.
Lab 7.2: Same design, another framework
Rebuild the supervisor with the OpenAI Agents SDK using handoffs or agents-as-tools. Note lines of code, tracing quality and how you tested it.
Expected: A short comparison in docs/adr/0007-multi-agent-framework.md.
Lab 7.3: Single versus multi (capstone increment)
Run 10 incident scenarios 3 times with the single agent and with the supervisor. Compare success, tokens, latency and cost.
Expected: A table and a decision on which design the capstone keeps.
Go deeper
Videos
- LangGraph: Multi-Agent Workflows · LangChain · ~24 min. Multi-agent workflows in LangGraph: supervisor and collaboration patterns.
- OpenAI Agents SDK Handoffs | Deep Dive Tutorial · James Briggs · ~35 min. A deep dive into handoffs in the OpenAI Agents SDK.
- Build Production-Ready AI Agents in Python with Pydantic AI · ArjanCodes · ~16 min. Building typed, production-style agents with Pydantic AI.
Further reading
- Article How we built our multi-agent research system · Anthropic. An orchestrator with parallel sub-agents in production, with the token costs and the failures.
- Article Don't Build Multi-Agents · Cognition. The counter-argument: shared context and single-threaded agents for coding tasks. Read it with the one above.
- Paper Why Do Multi-Agent LLM Systems Fail? · Cemri et al., 2025. A taxonomy of 14 failure modes from 150+ traces of real multi-agent frameworks.
- Docs Handoffs · OpenAI Agents SDK docs. How one framework passes control and context between agents.
GitHub repositories
- openai/openai-agents-python: Handoffs, agents-as-tools and the tracing integration; read the multi-agent examples.
- pydantic/pydantic-ai: Multi-agent applications: delegation and programmatic hand-off examples.
- crewAIInc/crewAI: Role-based crews and tasks, to compare with graph-based designs.
- langchain-ai/langgraph: The multi-agent concept docs: supervisor, hierarchical and network architectures.
Checkpoint quiz
Interview questions
- When is a multi-agent system better than a single agent? When is it worse?
- Design a supervisor with three specialists for incident response.
- How do you prevent context loss in handoffs?
- Compare LangGraph, the OpenAI Agents SDK and Pydantic AI for a production agent.
- How do you trace and debug a run that spans several agents?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).