Multi-Agent Architecture
Design and build systems with multiple collaborating agents using supervisor and peer patterns.
Prerequisites
- 1Completed the Getting Started guide
- 2Familiarity with at least one agent framework
- 3Understanding of async Python or TypeScript
What you will learn
- When to use multi-agent vs single-agent architecture
- Supervisor pattern vs peer-to-peer collaboration
- How to implement shared state between agents
- Practical examples with LangGraph and CrewAI
- Debugging techniques for multi-agent systems
When to Go Multi-Agent
Multi-agent architecture adds complexity. Only adopt it when you have a clear reason:
- Separation of concerns — Different parts of your task require fundamentally different expertise, tools, or model configurations.
- Parallel execution — Independent subtasks can run concurrently, reducing total latency.
- Quality through specialization — A focused agent with a narrow system prompt outperforms a generalist agent trying to do everything.
- Human-in-the-loop checkpoints — You need approval gates between stages of a pipeline.
If your task can be handled by a single agent with well-defined tools, start there. You can always decompose into multiple agents later.
Supervisor Pattern
In the supervisor pattern, a central orchestrator agent decomposes the task and delegates subtasks to specialized worker agents. The supervisor collects results and synthesizes the final output.
# Supervisor pattern with OpenAI Agents SDK
from agents import Agent, Runner
research_agent = Agent(
name="Researcher",
instructions="""You are a research specialist. Given a topic,
find key facts, statistics, and recent developments.
Be thorough and cite your reasoning.""",
)
writer_agent = Agent(
name="Writer",
instructions="""You are a professional writer. Given research
notes, write a clear, engaging article. Use short paragraphs
and concrete examples.""",
)
supervisor = Agent(
name="Supervisor",
instructions="""You manage a content creation pipeline.
1. Send the topic to the Researcher for research.
2. Send the research to the Writer for drafting.
3. Review the draft and provide the final output.""",
handoffs=[research_agent, writer_agent],
)
result = Runner.run_sync(supervisor, "Write a blog post about MCP servers")
print(result.final_output)
The supervisor delegates via handoffs. Each worker agent completes its task and hands control back to the supervisor, which decides the next step.
Peer Collaboration Pattern
In the peer collaboration pattern, agents communicate directly without a central orchestrator. This works well for creative brainstorming, debate, or review workflows.
# Peer collaboration with CrewAI
from crewai import Agent, Task, Crew, Process
researcher = Agent(
role="Senior Researcher",
goal="Find accurate, up-to-date information on the topic",
backstory="You are a meticulous researcher with 10 years of experience.",
verbose=True,
)
writer = Agent(
role="Technical Writer",
goal="Write clear, engaging technical content",
backstory="You specialize in making complex topics accessible.",
verbose=True,
)
reviewer = Agent(
role="Editor",
goal="Review content for accuracy and clarity",
backstory="You are a senior editor with a keen eye for detail.",
verbose=True,
)
research_task = Task(
description="Research the topic: AI agent frameworks in 2025",
expected_output="A detailed research brief with key findings",
agent=researcher,
)
writing_task = Task(
description="Write a 500-word article based on the research",
expected_output="A polished article ready for publication",
agent=writer,
)
review_task = Task(
description="Review the article for accuracy and suggest improvements",
expected_output="Final reviewed article with any corrections",
agent=reviewer,
)
crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research_task, writing_task, review_task],
verbose=True,
)
result = crew.kickoff()
print(result)
Debugging Multi-Agent Systems
Debugging multi-agent systems is significantly harder than single-agent systems. Here are practical tips:
- Enable verbose logging — Set
verbose=Trueon every agent to see the full reasoning chain. - Trace tool calls — Log every tool invocation with its input and output. Tools like LangSmith and Langfuse provide this out of the box.
- Visualize the graph — LangGraph lets you export your graph structure for visualization. Use
app.get_graph().draw_mermaid(). - Isolate agents — Test each agent individually before combining them. If the writer agent produces poor output, fix its prompt before debugging the supervisor.
- Add checkpoints — LangGraph supports persistent checkpoints. You can pause, inspect, and resume execution at any node.
# Visualize your LangGraph
print(app.get_graph().draw_mermaid())
# Add a checkpoint store for debugging
from langgraph.checkpoint.memory import MemorySaver
memory = MemorySaver()
app = graph.compile(checkpointer=memory)
# Run with a thread ID for persistent state
config = {"configurable": {"thread_id": "debug-session-1"}}
result = app.invoke({"topic": "AI agents"}, config)
Common Mistakes to Avoid
- !Using multi-agent when a single agent with good tools would be simpler and more reliable
- !Not defining clear boundaries between agent responsibilities, leading to overlapping work
- !Forgetting to handle failures — if one agent fails, the entire pipeline can stall
- !Making the supervisor agent too complex — keep its instructions focused on orchestration, not content
- !Not testing individual agents in isolation before combining them into a system