# 8. Multi-agent systems

When and how to use several agents. Supervisor and sub-agents, handoffs, orchestrator-workers, evaluator-optimizer loops, routing, debate, mixture of agents, and the costs of coordination.

Source: https://glamorous-boar.cloudvent.net/learn/multi-agent-systems/

---

## Why more than one agent?

A single agent with twenty tools and a long system prompt gets confused: tool choice degrades, instructions conflict, the context fills up. Splitting work across **specialised agents** helps when:

- sub-tasks need **different instructions, tools or models** (a researcher with web access, an analyst with a calculator);
- work can run **in parallel** (research five companies at once);
- you want **separation of duties** (one agent writes, another critiques);
- each agent's context stays **small and focused**.

It costs more calls, more latency and more ways to fail. Add agents only when a single agent demonstrably struggles.

## The core patterns

### Supervisor and sub-agents (handoff)

A **supervisor** agent receives the task and **delegates** pieces to **sub-agents**, each offered to it *as a tool* (`researcher(task, context)`). The supervisor reads their results and decides what to do next, possibly delegating again.

Design points:

- **Explicit handoffs**: each delegation is a tool call with a clear task, traced end to end.
- **Depth limits**: sub-agents may have their own sub-agents, but cap the depth (AgenticMind: 3).
- **Shared budgets**: a sub-agent's tokens and cost count toward the supervisor's limits.
- **Partial results**: a sub-agent that hits its limit should hand back what it has and why.
- **Failure sharing**: if a tool is permanently broken, tell every agent at once instead of letting the supervisor re-delegate the same doomed task.

### Orchestrator-workers (planner + parallel workers)

A **planner** splits a goal into independent, self-contained tasks; **workers** execute them in parallel; a **synthesizer** combines results. Ideal for research, analysis and batch processing. The key discipline: each task must make sense on its own, because a worker sees only its task.

### Evaluator-optimizer (critic loop, reflection)

A **generator** produces a draft; an **evaluator** (critic) checks it against criteria and returns feedback; the generator revises; repeat until the evaluator passes it or a round limit is hit. Separate deterministic **rule checks** (word count, required phrases) from **model-judged** criteria (tone, accuracy), and report both: rule results are facts, model judgements are opinions.

### Routing to specialists

A classifier or router sends each request to the right specialist (billing agent, technical agent, general assistant), and a join gathers whichever answer was produced. Cheap, predictable, and often all you need.

### Debate and mixture of agents

- **Debate** (Du et al., 2023): several agents answer independently, read each other's answers, and revise over rounds; the majority (or a judge) decides. Improves factuality and reasoning on some tasks.
- **Mixture of agents** (Wang et al., 2024): layers of proposer agents, each layer seeing the previous layer's answers, then an aggregator synthesises the final answer. Using *different* models adds diversity.

These are often implemented as reasoning strategies rather than separate agents (chapter 9).

## Coordination costs

| Cost | Mitigation |
|---|---|
| More model turns (each delegation costs at least two sub-agent turns plus a supervisor turn) | Delegate coarse tasks; give sub-agents enough tools to finish in one go |
| Latency | Parallelise independent work |
| Lost context between agents | Pass explicit context with each handoff |
| Error amplification | Critics, validation, limits, partial results |
| Debuggability | Traces that label which agent did what |

## Choosing a pattern

| Situation | Pattern |
|---|---|
| Distinct skills needed in an unpredictable order | Supervisor + sub-agents |
| Big task that splits into independent parts | Orchestrator-workers |
| Quality bar rarely met on the first try | Evaluator-optimizer |
| Known request categories | Routing |
| Hard question with a checkable answer | Debate / mixture, or a reasoning strategy |

## Try it in AgenticMind

| Pattern | Template | Nodes |
|---|---|---|
| Supervisor + sub-agents | *Research team* | Agent, Subagent (as tools) |
| Orchestrator-workers | *Plan and execute* | Planner, Loop (`for_each`, parallel), Agent, Loop End |
| Evaluator-optimizer | *Write with a critic* | Loop (`repeat`), LLM, Critic, Loop End (`next_state`) |
| Routing | *Ticket triage* | Router or Classifier, Join |
| Debate / mixture | *Think it through* | Reasoning (`debate`, `mixture_of_agents`) |

See [Multi-agent systems](/multi-agent/).

<Alert variant="tip" title="Key takeaways" text="Use several agents when sub-tasks need different instructions, tools or models, or can run in parallel. The core patterns are supervisor with sub-agents, orchestrator-workers, evaluator-optimizer and routing. Every extra agent costs turns and latency, so share budgets, cap depth, pass explicit context and trace everything."/>
