Multi-Agent
Supervisor-worker delegation across multiple autonomous agents.
Multi-Agent (Delegation / Supervision) — Overview
The multi-agent pattern uses multiple specialized agents coordinated by a supervisor. Each agent has its own tools, prompts, and domain expertise. The supervisor decides which agent to delegate to, interprets results, and orchestrates the overall task.
Evolves from: Orchestrator-Worker + Routing — adds agent-to-agent communication, shared state, and supervisor oversight.
Architecture
Figure: A supervisor agent routes subtasks to specialized worker agents, each with their own tools. Shared state enables agents to read each other's results. The supervisor synthesizes the final output.
How It Works
- Receive — The supervisor agent receives a complex task from the user.
- Analyze — The supervisor reasons about the task and identifies which worker agent(s) are needed.
- Delegate — The supervisor sends focused subtasks to worker agents via tool calls (e.g.,
delegate_to("research_agent", "Find data on X")). - Execute — Worker agents run autonomously, using their specialized tools to complete their subtasks. Each worker is a full agent (typically a ReAct loop).
- Return — Worker results are returned to the supervisor.
- Iterate — The supervisor may delegate additional tasks, refine previous results, or request corrections from workers.
- Synthesize — Once all needed work is done, the supervisor combines results into a final output.
Minimal Example
Produce a technical deep-dive — the supervisor delegates research, writing, and review to three specialized agents.
from patterns.multi_agent.code.python.multi_agent import MultiAgentSystem, SubAgent
# Each sub-agent can itself be a ReActAgent, RAGPipeline, etc.
system = MultiAgentSystem(
supervisor=your_llm,
agents=[
SubAgent(
name="researcher",
description="Finds papers, benchmarks, and technical details",
run=lambda task, ctx: research_agent.run(task).answer,
),
SubAgent(
name="engineer",
description="Writes technical content with code examples",
run=lambda task, ctx: engineer_agent.run(task).answer,
),
SubAgent(
name="editor",
description="Polishes, restructures, and ensures consistency",
run=lambda task, ctx: editor_agent.run(task).answer,
),
],
max_rounds=4,
)
result = system.run(
"Produce a technical deep-dive on LLM inference optimization for a developer audience"
)
# result.delegations → which agents were called and in what order (decided by supervisor)
# result.agent_outputs → each agent's contribution
# result.final_output → synthesized deliverable
Full implementation: [`code/python/multi_agent.py`](code/python/multi_agent.py)
Input / Output
- Input: A complex task requiring multiple specialized capabilities
- Output: A synthesized result combining work from multiple agents
- Delegation:
{agent: string, task: string, context?: object} - Shared state: Accumulated results accessible to all agents
Key Tradeoffs
| Strength | Limitation |
|---|---|
| Each agent is specialized and focused | High complexity — multiple agents to design, prompt, and debug |
| Naturally handles multi-domain tasks | Cost scales with number of agents and delegation rounds |
| New agents can be added without changing others | Inter-agent communication design is critical and hard |
| Supervisor provides oversight and quality control | Supervisor is a single point of failure |
| Parallelizable when worker tasks are independent | Shared state management adds coordination overhead |
When to Use
- Tasks spanning multiple domains (research + code + writing)
- When different subtasks need different tool sets
- When the system needs distinct "expertise areas"
- Large-scale tasks that benefit from divide-and-conquer
- When you want clear separation of concerns between capabilities
When NOT to Use
- When a single agent with multiple tools suffices — use ReAct
- When the task decomposition is static — use Orchestrator-Worker
- For simple routing without agent autonomy — use Routing
- When the overhead of multiple agents isn't justified by the task complexity
Related Patterns
- Evolves from: Orchestrator-Worker + Routing — see evolution.md
- Workers use: ReAct (each worker runs an agent loop), Tool Use
- Combines with: Memory (shared memory across agents), Plan & Execute (supervisor generates a plan, workers execute steps)
Deeper Dive
- Design — Agent registry, communication protocols, shared state, supervisor prompting, worker design
- Implementation — Pseudocode, delegation mechanics, state management, testing strategies
- Evolution — How multi-agent evolves from orchestrator-worker and routing