AI Engineer Roadmap All lessons Interactive Quiz GitHub

Multi-Agent Systems

Advanced · 9 min read · Updated · By Saurabh Pathak

In short: A multi-agent system splits a job across several LLM "agents", each with its own role, prompt, and tools, that pass work between them.

Play the interactive lesson: Multi-agent systemsRead on GitHub
On this page
  1. Explain it like I'm new
  2. Watch it
  3. How it works
  4. Code example
  5. When to use it / when not to
  6. Common mistakes
  7. Recap
  8. Interview questions
  9. Go deeper

Level: Advanced · Reading time: 9 min · Phase: 4 · Agentic AI

Before you start: Agent Loops and Reflection. You should know how a single agent loops over tools, and how a critic step improves a draft.

Explain it like I'm new

A newspaper doesn't have one person do everything. An editor plans the stories, reporters write them, and a fact-checker reviews them before print. Each has a narrow job and different tools.

A multi-agent system copies that structure. Common roles:

"Agent" here often just means "an LLM call with its own system prompt and tool list". Several agents can even use the same model.

Why split? A single agent with 40 tools and a giant prompt gets confused. Smaller agents with focused prompts are easier to test and improve one at a time. Work can also run in parallel. The price: more model calls, more cost, and more places for things to go wrong.

Words to know:

Watch it

Multi-agent systems: Several agents with different roles pass work to each other.
Multi-agent systems: Several agents with different roles pass work to each other.

It plays on a loop. Read the caption in the box, one step at a time. Want to go at your own pace? Step through it with Previous and Next.

How it works

Common shapes:

  1. Pipeline (sequential): planner → worker → critic, each passing its output to the next.
  2. Orchestrator-workers: a central agent sends subtasks to workers (possibly in parallel) and combines results.
  3. Supervisor / router: a supervisor picks which specialist handles each step.
  4. Debate / peer review: agents propose and critique each other's answers.
flowchart LR
    U[goal] --> P[planner]
    P --> W[worker]
    W --> C{critic: problems?}
    C -- yes --> W
    C -- no --> H{risky action?}
    H -- yes --> A[human approval] --> X[execute]
    H -- no --> X
    X --> R[result]
    G[[guardrails: allowlist + max steps]] -. checks every tool call .- W

Worked example

Real output of python agent_multi.py for the goal agents and email it:

plan: ['write_text', 'send_email']
write_text -> Draft about agents and email it.
critic: ['needs a concrete example']
add_example -> Draft about agents and email it. Example: a support bot that looks up orders.
human approved send_email
send_email -> EMAIL SENT: Draft about agents and email it. Example: a support bot that looks up orders.
  1. The planner turns the goal into two steps.
  2. The worker runs write_text and produces a short draft.
  3. The critic says the draft needs a concrete example, so the worker revises it with add_example.
  4. send_email is marked risky, so the code asks a human first. Here the demo approves automatically.
  5. Only then does the email go out.

If the allowlist leaves out send_email, the same run stops at step 4 with status blocked. The email is never sent, because the check is in code.

Design rules:

Code example

agent_multi.py implements planner → worker → critic with a human approval gate and guardrails, fully offline:

from agent_multi import run_pipeline

def approver(tool, preview):
    print(f"Approve {tool}? -> {preview!r}")
    return True                                   # a real app would ask a person

result = run_pipeline("agents and email it", approver)
print(result["status"])                           # done
for line in result["log"]:
    print(" ", line)
# plan: ['write_text', 'send_email']
# write_text -> Draft about agents and email it.
# critic: ['needs a concrete example']
# add_example -> Draft about agents and email it. Example: a support bot that looks up orders.
# human approved send_email
# send_email -> EMAIL SENT: ...

blocked = run_pipeline("agents and email it", approver, allowed_tools=("write_text", "add_example"))
print(blocked["status"], blocked["log"][-1])      # blocked guardrail: tool 'send_email' is not on the allowlist

The tests in test_agent_multi.py cover reflection, approval rejection, the allowlist, and the step cap.

In real projects, frameworks such as LangGraph (graph of agent nodes with shared state), CrewAI, or AutoGen provide orchestration, state, and interrupts. See Phase 5 · Frameworks.

When to use it / when not to

Single agentMulti-agent
Simplicityhighlow
Cost per tasklowerhigher (more calls)
Debuggingeasierharder (handoffs)
Specializationlimitedstrong
Parallelismlimitednatural

Common mistakes

Recap

If you remember only three things:

Interview questions

1. When would you choose a multi-agent design over a single agent? <details><summary>Answer</summary> When sub-tasks need different prompts, tools, or expertise; when they can run in parallel; or when one agent's context and tool list became too large to work reliably. Otherwise a single agent is simpler and cheaper. </details>

2. Describe an orchestrator-workers pattern. <details><summary>Answer</summary> A central LLM breaks a task into subtasks at run time, delegates each to worker LLM calls (often in parallel), then combines their results. It suits tasks where you can't predict the subtasks in advance. </details>

3. Where should guardrails live in a multi-agent system? <details><summary>Answer</summary> In the orchestration code that executes tools, outside any agent's prompt: tool allowlists per agent, global step and budget limits, argument validation, and human approval for risky actions. Agents can be manipulated; code checks can't be argued with. </details>

Go deeper

Prev: Agent Loops · Next: Human in the Loop · Back to phase: Phase 4