Task 1.5

Multi-Agent Systems

Multi-agent systems use multiple specialized Claude instances that collaborate to solve complex problems. Each agent has a focused role, specialized tools, and a targeted system prompt.

Manager-Worker Pattern

The manager-worker pattern uses one agent (the manager) to decompose tasks and delegate subtasks to specialized worker agents. The manager coordinates the workflow, aggregates results, and handles failures. Worker agents focus on specific capabilities — one might handle data retrieval, another handles analysis, and a third handles report generation.

This pattern works well when tasks naturally decompose into independent subtasks that benefit from specialized prompts and tools.

Pipeline Pattern

The pipeline pattern chains agents sequentially, where each agent's output becomes the next agent's input. Unlike prompt chaining (which uses direct API calls), pipeline agents maintain their own context and can use tools. For example: an extraction agent pulls data from documents, a validation agent checks data quality, and a formatting agent produces the final output.

Pipelines are effective when processing requires distinct expertise at each stage and when intermediate results need validation before proceeding.

When Not to Use Multi-Agent

Multi-agent systems add latency, cost, and complexity. A single well-designed agent with multiple tools often outperforms a multi-agent system for tasks that are interconnected or require shared context. Multi-agent overhead includes: inter-agent communication, context synchronization, error propagation between agents, and debugging complexity.

Use multi-agent only when: agents need fundamentally different tool sets, the task naturally decomposes into independent subtasks, you need different security boundaries for different operations, or a single agent's context window would be overwhelmed.

Key Concept

Shared Nothing, Shared Context

Multi-agent systems work best when agents share minimal context. Each agent should be self-contained with its own system prompt and tools. When agents need to share information, pass it explicitly through structured messages — never rely on shared mutable state. The less agents need to coordinate, the more robust the system.

Exam Traps

EXAM TRAP

Assuming multi-agent is always better than single-agent

Multi-agent systems add overhead. The exam frequently tests whether you can identify when a single agent with multiple tools is the simpler, more effective solution.

EXAM TRAP

Confusing multi-agent with multi-turn conversation

A multi-turn conversation with one agent is not a multi-agent system. Multi-agent requires multiple distinct agent instances with separate configurations.

EXAM TRAP

Ignoring context isolation between agents

Each agent in a multi-agent system has its own conversation context. Information must be explicitly passed between agents — they do not automatically share memory.

Check Your Understanding

You are building a code review system. It needs to check style, find bugs, assess security, and generate a summary report. Each check requires different analysis context. Which approach is most appropriate?

Build Exercise

Build a Manager-Worker Agent System

Advanced60 minutes

What you'll learn

  • Design a multi-agent architecture
  • Implement manager-worker coordination
  • Handle inter-agent communication
  • Compare multi-agent vs. single-agent performance
  1. Design the agent architecture: define the manager's role, identify 2-3 worker agents, and specify what information flows between them.

    WHY: Architecture design before implementation prevents costly rework.

    YOU SHOULD SEE: A clear diagram or description of agents, their responsibilities, and communication flows.

  2. Implement the worker agents. Each should have a focused system prompt, specific tools, and return structured output.

    WHY: Workers should be independently testable units with clear inputs and outputs.

    YOU SHOULD SEE: Each worker agent correctly handles its specialized subtask.

  3. Implement the manager agent. It should decompose the input task, dispatch to workers, collect results, and produce a unified output.

    WHY: The manager coordinates the workflow and handles the complexity of multi-agent orchestration.

    YOU SHOULD SEE: The manager correctly delegates to workers and synthesizes their outputs.

  4. Add error handling: what happens when a worker fails? Implement retry logic and fallback behavior in the manager.

    WHY: Multi-agent systems have more failure modes than single agents. Robust error handling is essential.

    YOU SHOULD SEE: The system gracefully handles worker failures without crashing.

Sources

Previous

Claude Agent SDK