Library
Claude Code Mastery · Chapter 7 of 10
Chapter 07

Advanced
Agent Systems

From one lone loop to coordinated teams of specialists.

Multi-AgentRAGEvalsArchitecture
A Handbook For Builders
Advanced
Agent Systems
Chapter 07
The Claude Code Handbook
Prologue

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.

Section 7.0

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.

Part I · Patterns

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.

Claude Code — Terminal
Screenshot placeholder
Diagram of a three-agent system with arrows showing message passing between Planner, Worker, and Critic.
Figure — Diagram of a three-agent system with arrows showing message passing between Planner, Worker, and Critic.
Part I · Patterns

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.
Part I · Patterns

3. Orchestrator Pattern

A single "boss" agent decides who does what, when, and passes results back. Great when tasks are heterogeneous.

diagramclaude-code
Orchestrator
   ├─▶ Writer
   ├─▶ Researcher
   └─▶ Fact-checker
        │
        ▼
   Orchestrator (assemble & return)
Part I · Patterns

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.

Part I · Patterns

5. Critic / Reviewer Loop

Have one agent generate, another critique, then re-generate. Two rounds catch 80% of hallucinations.

Part I · Patterns

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.

Claude Code — Terminal
Screenshot placeholder
Kanban-style plan.md rendered as a checklist with each item owned by a different worker agent.
Figure — Kanban-style plan.md rendered as a checklist with each item owned by a different worker agent.
Part II · Knowledge

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.

diagramclaude-code
docs → chunk → embed → vector DB
                                   │
                       query → embed → top-k → prompt → answer
Part II · Knowledge

8. 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.
Part II · Knowledge

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.

Part III · Quality

10. Evaluating Agents

  1. Write a small dataset of 20–50 realistic tasks with expected outcomes.
  2. Run the agent on all of them nightly.
  3. Score with rubric prompts + regex + human spot-checks.
  4. Track pass rate over time; refuse to ship regressions.
Claude Code — Terminal
Screenshot placeholder
Dashboard showing eval pass rate trending upward across three weeks of agent improvements.
Figure — Dashboard showing eval pass rate trending upward across three weeks of agent improvements.
Part III · Quality

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.
Part IV · Build

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.

Claude Code — Terminal
Screenshot placeholder
Terminal showing three agents exchanging structured messages until the Editor approves the final draft.
Figure — Terminal showing three agents exchanging structured messages until the Editor approves the final draft.