One brain is not enough.
A single agent solves point tasks. Real products — the ones that survive contact with paying customers — are usually small teams of agents that plan, execute, criticize and iterate together. This chapter is the leap from prototypes to systems.
Beyond a Single Loop
Adding more agents does not automatically help. In fact, most naive multi-agent setups perform worse than a single well-designed loop. Adopt multi-agent patterns only when you can name the specific weakness they fix.
1. Multi-Agent Systems
A multi-agent system is any setup where two or more LLM-driven roles exchange messages or artifacts to achieve a joint goal. Costs add up quickly — plan the roles like you would plan a small team.
2. Assigning Roles
- Planner — breaks the goal into sub-tasks.
- Worker — executes one sub-task at a time.
- Critic — reviews output against acceptance criteria.
- Router — decides which specialist should handle the next step.
3. Orchestrator Pattern
A single "boss" agent decides who does what, when, and passes results back. Great when tasks are heterogeneous.
Orchestrator
├─▶ Writer
├─▶ Researcher
└─▶ Fact-checker
│
▼
Orchestrator (assemble & return)4. Swarm Pattern
Peer agents pass control by handing off "roles" instead of routing through a central boss. Good when handoffs are rare and each agent owns a clear stage.
5. Critic / Reviewer Loop
Have one agent generate, another critique, then re-generate. Two rounds catch 80% of hallucinations.
6. Planner / Worker Split
The planner writes a plan.md; workers each execute one step and mark it done. This mirrors how humans run projects.
7. Retrieval-Augmented Generation (RAG)
Store domain knowledge as embeddings; retrieve the top-k chunks and inject them into the prompt so the model can cite instead of guess.
docs → chunk → embed → vector DB
│
query → embed → top-k → prompt → answer8. Long-Running Tasks
- Break work into idempotent steps you can retry.
- Persist state to disk between steps — never rely on memory.
- Emit progress events so a UI can show status.
- Add human approval before irreversible actions.
9. Managing Shared State
Shared state usually lives in three places: a job record in Postgres, files in a sandbox folder, and messages in a queue. Keep each with a clear owner.
10. Evaluating Agents
- Write a small dataset of 20–50 realistic tasks with expected outcomes.
- Run the agent on all of them nightly.
- Score with rubric prompts + regex + human spot-checks.
- Track pass rate over time; refuse to ship regressions.
11. Safety and Human-in-the-loop
- Require confirmation for delete/send/deploy actions.
- Log every tool call, prompt, and response for audit.
- Redact PII before sending to third-party APIs.
- Rate-limit agent runs per user.
12. Project — Content Studio Swarm
Build a three-agent studio that turns a topic into a finished blog post: Researcher, Writer, and Editor. The Orchestrator coordinates handoffs and stops after two edit rounds.