← Back to Table of Contents

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.

Single Agent vs. Multi-Agent
One Agent Does 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
Specialized Agents Collaborate
  • 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
πŸ‘€ User request
🎯 Supervisor Agent Delegates tasks, coordinates, synthesizes
πŸ”
Researcher
Web search, data gathering
πŸ’»
Coder
Write and execute code
✍️
Writer
Draft reports and docs
πŸ”
Reviewer
Quality check 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
πŸ€– Triage Agent
πŸ”§ Tech Support
πŸ’° Billing Agent
πŸ“¦ Returns Agent
# 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.

Debate Pattern
❓ Question / Task
🟒
Agent A (Pro)
Argues for position X
πŸ”΄
Agent B (Con)
Argues against X
βš–οΈ Judge Agent: evaluates both arguments
πŸ“‹ Final verdict with reasoning

4. Pipeline Pattern

Agents execute in sequence, each processing and transforming the output of the previous one.

Pipeline Pattern
πŸ“ Draft Agent
πŸ” Review Agent
✨ Polish Agent
βœ… QA Agent

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