Multi-Agent Architectures
Supervisor, Pipeline, Debate & Swarm patterns with architecture diagrams.
When One Agent Isn't Enough
Complex tasks benefit from multiple specialized agents. But "just add more agents" is a recipe for chaos. You must choose the right coordination pattern based on the task structure.
1. Supervisor Pattern
A single "manager" agent receives the user request, plans the subtasks, delegates to specialized worker agents, and aggregates results.
Best for: Complex orchestration with clear subtask decomposition. Reports, analysis, code generation.
2. Pipeline Pattern
Agents process sequentially. Each agent refines the output of the previous one. Think assembly line.
Best for: Content creation, CI/CD automation, data processing pipelines.
3. Debate Pattern
Multiple agents argue opposing perspectives and a judge agent selects the best argument. Reduces hallucination through adversarial verification.
Best for: Fact-checking, risk analysis, decision-making under uncertainty.
4. Swarm Pattern (OpenAI)
Agents self-organize without a central coordinator. Each agent has a handoff() function to transfer control to another agent when the task is outside its scope.
Best for: Customer support with departments, triage bots, open-ended workflows.
Which Pattern Should You Use?
| Pattern | Control | Latency | When to Use |
|---|---|---|---|
| Supervisor | Centralized | Higher | Complex orchestration with subtask planning |
| Pipeline | Sequential | Predictable | Linear workflows (generate โ review โ publish) |
| Debate | Adversarial | High | High-stakes decisions, fact verification |
| Swarm | Decentralized | Low | Dynamic routing, customer support triage |
Code Example
OpenAI Swarm pattern โ agents with handoff functions.
1from openai import OpenAI
2
3client = OpenAI()
4
5AGENTS = {
6 "sales": {
7 "system": "You are a sales agent. If user asks about refunds, handoff to refund_agent.",
8 "tools": ["check_inventory", "process_order"]
9 },
10 "refund": {
11 "system": "You are a refund agent. Process return requests.",
12 "tools": ["lookup_order", "process_refund"]
13 }
14}
15
16def run_agent(agent_name: str, messages: list) -> dict:
17 agent = AGENTS[agent_name]
18 response = client.chat.completions.create(
19 model="gpt-4o",
20 messages=[
21 {"role": "system", "content": agent["system"]},
22 *messages
23 ]
24 )
25 reply = response.choices[0].message.content
26
27 # Simple handoff detection
28 if "handoff to refund_agent" in reply.lower():
29 print(f"Handoff: {agent_name} -> refund")
30 return run_agent("refund", messages)
31
32 return {"agent": agent_name, "response": reply}
33
34result = run_agent("sales", [
35 {"role": "user", "content": "I want to return my order #12345"}
36])Use Cases
Common Mistakes
Interview Insight
Relevance
High - Core system design question at AI-first companies.