When one agent isn't enough — orchestrate multiple specialized agents to tackle complex tasks. Understand collaboration patterns that solve problems individual agents can't.
A single agent is jack-of-all-trades, master of none. A multi-agent system assigns specific roles: one agent researches, one analyzes, one writes. Like a development team working on a product.
A single developer can build an app, but a team is better: frontend engineer handles UI, backend engineer handles API, DevOps engineer handles deployment. Each specializes, then they integrate. Multi-agent systems work the same way: each agent is an expert, they coordinate.
Complex tasks broken into specialized subtasks. Each agent excels at one thing.
Agents work in parallel (or pipeline) to speed up overall task completion.
One agent's output becomes another's input. Iterative refinement improves quality.
A critic agent can verify other agents' work, catching mistakes before delivery.
There are four proven patterns for orchestrating multiple agents. Each suits different task types.
One supervisor agent delegates to specialists. The supervisor breaks down the goal, assigns subtasks, gathers results, and synthesizes them. Classic orchestration pattern.
User: "Write a product launch plan"
↓
Supervisor Agent:
- Breaks into: Market Analysis, Budget Planning, Timeline, Risk Mitigation
- Assigns to specialists
↓
Market Analyst: "Competitors, target audience, positioning"
Budget Planner: "Cost breakdown, revenue projections"
Timeline Manager: "Phases, milestones, dependencies"
Risk Analyst: "Risks, mitigation strategies"
↓
Supervisor: Gathers results, synthesizes into final plan
↓
User: Complete launch plan
Agents work together at the same level. Each can initiate messages to others. Useful for exploratory problems where the solution emerges from discussion.
Output of one agent becomes input to the next. Linear workflow. Researcher → Analyst → Writer → Editor. Clear data flow.
Multiple agents argue for different viewpoints, a judge/critic decides. Excellent for improving quality by exposing weaknesses in reasoning.
One orchestrator, many specialists. Best for: well-defined tasks with clear subtasks.
All agents equal, self-coordinating. Best for: exploratory, collaborative work.
Output → Input chain. Best for: transform-heavy workflows (research → analysis → writing).
Opposing viewpoints, judge decides. Best for: quality improvement, difficult decisions.
Agents need a way to communicate: pass data, request information, coordinate actions. There are several approaches, each with tradeoffs.
Agents send structured messages to each other. Asynchronous, loosely coupled. Good for pipelines.
All agents read/write to a shared state dictionary. Tightly coupled but fast. Risk of conflicts.
Central "blackboard" where agents post findings. Others read, build on ideas. Great for exploratory work.
Persistent storage for intermediate results. Survives agent restarts. Best for production.
Let's implement the supervisor pattern in Python. This is the most practical pattern for production systems.
class Agent: def __init__(self, name: str, role: str): self.name = name self.role = role self.client = anthropic.Anthropic() def work(self, task: str) -> str: """Execute a task and return result.""" response = self.client.messages.create( model="claude-opus-4-6", max_tokens=2048, system=f"You are a {self.role}. Your name is {self.name}. Do excellent work.", messages=[{"role": "user", "content": task}] ) return response.content[0].text class SupervisorAgent: def __init__(self): self.supervisor = Agent("Supervisor", "Project Manager") self.specialists = [ Agent("Alice", "Market Research Analyst"), Agent("Bob", "Financial Analyst"), Agent("Carol", "Project Manager") ] def run(self, goal: str) -> str: """Supervisor breaks goal into subtasks, delegates to specialists.""" # 1. Supervisor analyzes goal and creates subtasks subtasks_prompt = f"""Goal: {goal} Break this into 3 specific subtasks for different specialists: 1. For a Market Research Analyst 2. For a Financial Analyst 3. For a Project Manager Format: SUBTASK 1: [task for analyst 1] SUBTASK 2: [task for analyst 2] SUBTASK 3: [task for analyst 3]""" subtasks_text = self.supervisor.work(subtasks_prompt) # 2. Parse subtasks (simple regex approach) subtasks = [] for line in subtasks_text.split("\n"): if "SUBTASK" in line: subtasks.append(line) # 3. Distribute to specialists results = [] for i, specialist in enumerate(self.specialists): if i < len(subtasks): result = specialist.work(subtasks[i]) results.append({ "specialist": specialist.name, "result": result }) # 4. Supervisor synthesizes results synthesis_prompt = f"""You have collected the following results from specialists: {chr(10).join([f"{r['specialist']}: {r['result'][:300]}" for r in results])} Synthesize these into a cohesive final deliverable for the goal: {goal} Provide a comprehensive, well-structured final answer.""" final_answer = self.supervisor.work(synthesis_prompt) return final_answer # Usage supervisor = SupervisorAgent() result = supervisor.run("Create a launch strategy for a new SaaS product") print(result)
Two agents argue for opposite positions. A judge evaluates both and decides. This improves answer quality by forcing reasoning to surface weaknesses.
class DebateAgents: def __init__(self): self.pro_agent = Agent("Pro", "Advocates FOR the proposal") self.con_agent = Agent("Con", "Advocates AGAINST the proposal") self.judge = Agent("Judge", "Evaluates both sides fairly") def debate(self, question: str) -> str: # Round 1: Pro argues FOR pro_argument = self.pro_agent.work( f"Argue STRONGLY FOR: {question}\nBe compelling and data-driven." ) # Round 2: Con argues AGAINST con_argument = self.con_agent.work( f"Argue STRONGLY AGAINST: {question}\nAddress Pro's points if possible." ) # Round 3: Judge decides judgment = self.judge.work( f"""Question: {question} Pro argument: {pro_argument} Con argument: {con_argument} Evaluate both arguments. Which is stronger? Why? What's the best decision?""" ) return f""" PRO ARGUMENT: {pro_argument} CON ARGUMENT: {con_argument} JUDGE'S DECISION: {judgment}""" # Usage debate = DebateAgents() decision = debate.debate("Should we adopt microservices architecture?") print(decision)
Strategic decisions, architecture choices, hiring decisions. When the answer has legitimate pros and cons, debate surfacing both sides improves quality.
Multi-agent systems are powerful but introduce new problems. Understanding challenges is critical for success.
More agents = more communication. Message passing, context sharing, state management. For simple tasks, the overhead outweighs benefits. Single-agent may be faster.
Agent A asks Agent B, who asks Agent C, who asks Agent A. Uncontrolled loops waste tokens and time. Add strict termination conditions and loop detection.
Different agents disagree or contradict each other. You need a judge or arbitrator. Build conflict resolution into your system design.
Multiple agents = multiple LLM calls. 5 agents × 10 iterations = 50 API calls. Costs add up fast. Monitor and budget carefully.
Not every problem needs multi-agent. Sometimes a single well-engineered agent is better.
- Complex, multi-step workflows - Tasks needing specialization - Quality validation (critic agent) - Exploratory/debate scenarios - Team-like coordination
- Single-step tasks - Simple classification/summarization - Latency-critical applications - Cost-sensitive deployments - Well-defined linear workflows
Build a single agent first. If it can't handle the task, add specialists. Add a critic agent if quality is an issue. This incremental approach prevents over-engineering.
1. In the supervisor pattern, what does the supervisor do?
2. The debate pattern is best for what type of problem?
3. What's a major risk with multi-agent systems?
4. When is a single agent better than multiple agents?
Multi-agent systems apply specialization to complex problems. Four patterns dominate: Supervisor (one orchestrator, many specialists), Peer-to-Peer (flat collaboration), Pipeline (sequential transformation), and Debate (adversarial quality improvement). Communication protocols determine how agents coordinate: message passing, shared state, blackboard, or database. Challenges include coordination overhead, infinite loops, conflicting outputs, and cost explosions. Not every problem needs multi-agent — single agents are simpler and cheaper for straightforward tasks. Use multi-agent for genuinely complex, multi-step problems where specialization adds value.
Next up → Topic 17: Full-Stack AI Agent Project
Capstone project: build a complete, production-ready multi-agent research system.