Chapter 8 β Multi-Agent Systems
βOne agent is useful. Multiple agents collaborating is transformative.β β Andrew Ng
Why Multiple Agents?
A single agent has limits: it can get confused with too many tools, struggles with very complex tasks, and has one perspective. Multi-agent systems solve this by having specialized agents collaborate β the same way a team of humans is more effective than one person doing everything.
- 20+ tools β confused tool selection
- One system prompt tries to cover all roles
- Context window fills with everything
- Hard to debug β one monolithic loop
- No checks and balances
- Each agent has 2β5 focused tools
- Each has a clear, specific role
- Context stays relevant per agent
- Debug each agent independently
- Agents can review each other's work
Multi-Agent Architectures
1. Supervisor Pattern
A central supervisor agent coordinates worker agents. It decides who works on what and synthesizes their output.
# Supervisor pattern in LangGraph
from langgraph.graph import StateGraph, START, END
def supervisor(state):
"""Decides which agent to route to next."""
response = llm.invoke(f"""
You are a supervisor managing these agents: researcher, coder, writer.
Current task: {state["task"]}
Progress so far: {state["results"]}
Which agent should work next? Or should we finish?
Respond with: researcher, coder, writer, or FINISH
""")
return {"next_agent": response.content.strip().lower()}
def researcher(state):
"""Research agent with web search tools."""
result = research_agent.invoke(state["task"])
return {"results": state["results"] + [result]}
# Build the graph
graph = StateGraph(AgentState)
graph.add_node("supervisor", supervisor)
graph.add_node("researcher", researcher)
graph.add_node("coder", coder)
graph.add_node("writer", writer)
graph.add_edge(START, "supervisor")
graph.add_conditional_edges("supervisor", route_to_agent)
2. Swarm Pattern
Agents hand off to each other directly β no central coordinator. Each agent decides when to transfer control to another.
# Swarm pattern (OpenAI Agents SDK style)
from agents import Agent, handoff
triage_agent = Agent(
name="Triage",
instructions="Route the customer to the right department.",
handoffs=[
handoff(tech_support_agent, "Technical issues"),
handoff(billing_agent, "Billing questions"),
handoff(returns_agent, "Returns and refunds"),
]
)
tech_support_agent = Agent(
name="Tech Support",
instructions="Help users with technical problems.",
tools=[search_docs, check_status],
handoffs=[handoff(triage_agent, "Not a tech issue")],
)
3. Debate Pattern
Two agents argue opposing positions. A judge agent evaluates and picks the best answer. Great for reducing hallucination and improving accuracy.
4. Pipeline Pattern
Agents execute in sequence, each processing and transforming the output of the previous one.
Communication Between Agents
Agents communicate through messages β structured data passed between them.
| Method | How It Works | Example |
|---|---|---|
| Shared state | All agents read/write to a common state object | LangGraphβs state dict |
| Message passing | Agents send messages directly to each other | AutoGen conversations |
| Handoffs | One agent transfers the entire conversation to another | OpenAI Swarm SDK |
| Blackboard | Shared workspace anyone can write to | Research boards, shared docs |
When to Use Multi-Agent
| Scenario | Single Agent | Multi-Agent |
|---|---|---|
| Simple Q&A with search | β | Overkill |
| Customer support routing | β | β Swarm pattern |
| Research report with code + writing | β | β Supervisor pattern |
| Code review | β | β Pipeline pattern |
| Complex decision making | β | β Debate pattern |
Real-World Multi-Agent Systems
| Project | Architecture | What It Does |
|---|---|---|
| ChatDev | Pipeline | Agents role-play as CEO, CTO, programmer, tester to build software |
| MetaGPT | Supervisor | Multi-agent framework for complex software projects |
| AutoGen | Message passing | Microsoftβs framework for multi-agent conversations |
| CrewAI | Task-based | Agents with roles, tools, and tasks β accessible multi-agent |
Whatβs Next
Now that you understand agent architectures from single to multi-agent, letβs survey the frameworks and SDKs that make building agents practical.
Next: Chapter 9 β Agentic Frameworks & SDKs β
β Previous: Chapter 7 β Planning & Reasoning Β· Next: Chapter 9 β Agentic Frameworks & SDKs β
Last updated: April 2026