Introduction to Multi-Agent Systems

Learn why and when to use several agents instead of one: the benefits and costs of multi-agent systems, single-agent versus multi-agent designs, and how agent specialization reduces prompt size and speeds up work.

25 minIntermediateCode Examples

The Core Idea: A multi-agent system splits a big job among several agents, each with its own role, tools and instructions. Specialization keeps each agent's prompt small and lets work run in parallel, but it adds coordination cost.

  1. Beginner: Why Multiple Agents?

A single agent with fifty tools and a long list of duties becomes confused, slow and expensive. Human teams solve the same problem by specializing: a researcher, an analyst and an assistant each do what they are best at.

ReasonWhat it means
SpecializationEach agent has a focused role and a few tools, so it picks the right tool more often
Smaller promptsFewer tool descriptions and instructions per call
Parallel workIndependent tasks run at the same time
Separation of concernsA writer and a reviewer can check each other
Easier to improveYou can test and upgrade one agent without touching the rest

Analogy: One employee doing sales, support, accounting and engineering will be mediocre at all of them. A team with clear roles works better, as long as it communicates well.

  1. Beginner: Single-Agent vs. Multi-Agent

Single agentMulti-agent system
DesignOne loop, all toolsSeveral loops with different roles
CostLowerHigher, from extra model calls and messages
SpeedSequentialCan be parallel
DebuggingEasier, one traceHarder, many traces and interactions
PredictabilityHigherLower
Best forFocused tasks with a few toolsBroad tasks with distinct skills

Rule of thumb: Start with one agent. Add more only when you can show that one agent is failing because of too many tools, too long a prompt, or tasks that could run in parallel.

  1. Medium: Agent Specialization

A specialist agent is defined by three things: a role in its instructions, a small set of tools, and often a different model, such as a cheaper one for simple work.

SpecialistToolsTypical job
Researcherweb_search, read_pageFind and read sources
Analystsql_query, make_chartAnalyze data
Assistantsend_email, write_fileTake actions

In the code: The generalist needs a 1,160-token prompt on every call. The researcher needs only 570, the analyst 640, and the assistant 550. Less to read means lower cost, less confusion and faster calls.

  1. Medium: The Speed-Up From Parallel Specialists

When tasks need different skills and do not depend on each other, specialists can work at the same time.

In the code: Six tasks take 18 seconds for one agent in sequence. With three specialists in parallel, the slowest specialist finishes after 8 seconds, because the researcher has 8 seconds of work and the others have less.

The total time is set by the busiest specialist, so balancing the workload matters.

  1. Advanced: The Hidden Costs

CostWhy it appearsMitigation
CoordinationAgents need messages, handoffs and mergingClear interfaces and few agents
Duplicated contextEach agent may need the same backgroundShare a common context store
Error compoundingA mistake by one agent feeds the nextValidate at each handoff
Conflicting actionsTwo agents change the same thingShared state with version checks
Harder debuggingMany agents, many tracesTrace every message with a run id
More tokensEvery extra agent adds callsUse small prompts and cheaper models for easy roles

Do not over-split. More agents is not better by itself. Many tiny agents with overlapping duties usually mean more bugs and a bigger bill.

  1. Visual Explanation: Generalist vs. Specialists: Prompts and Time

The figure compares the prompt size of one generalist with three specialists, then shows the time saved by working in parallel.

Part 1 · One Generalist vs. Three SpecialistsPrompt size per model call
Generalist1 agent, 6 tools
Instructions 300 tokens
↓
All six tool descriptions
↓
1,160 tokens on every call
Specialists3 agents, 2 tools each
Researcher 570
↓
Analyst 640
↓
Assistant 550
↓
About half the prompt per agent
Part 2 · Time for Six TasksSequence vs. parallel
One agent
In sequence
18 seconds.
Three specialists
In parallel
8 seconds.
Workload
Researcher 8, analyst 7, assistant 3
The busiest sets the time.
Cost
Coordination
Extra messages and merging.
Click to see when one agent is still betterCompare ▼
If the task is small, has only a few tools, or its steps must follow each other closely, the coordination cost of several agents outweighs the benefit. Start simple.

Part 1 uses the token counts from the code. Part 2 uses the time numbers. Open the bar to see when a single agent is still the better choice.

  1. Python Implementation: Comparing One Agent With a Team of Specialists

This script counts the prompt tokens needed by a generalist with six tools versus three specialists with two tools each, and compares the time to finish six tasks in sequence against a parallel team.

single_vs_multi_agent.pyPython 3.10+ · standard library only
# One generalist agent vs a team of specialistsTOOL_TOKENS = {"web_search": 150, "read_page": 120, "sql_query": 180, "make_chart": 160, "send_email": 140, "write_file": 110}BASE_INSTRUCTIONS = 300                       # tokens of instructions every agent needs specialists = {    "researcher": ["web_search", "read_page"],    "analyst": ["sql_query", "make_chart"],    "assistant": ["send_email", "write_file"],} def prompt_tokens(tools):    return BASE_INSTRUCTIONS + sum(TOOL_TOKENS[t] for t in tools) generalist = prompt_tokens(list(TOOL_TOKENS))print("Generalist prompt:", generalist, "tokens on every model call")for name, tools in specialists.items():    print(name.ljust(11), "prompt:", prompt_tokens(tools), "tokens |", len(tools), "tools") # Time: tasks that need different skills can run at the same timetasks = [("researcher", 5), ("analyst", 4), ("researcher", 3), ("assistant", 2), ("analyst", 3), ("assistant", 1)]single_agent_time = sum(seconds for _, seconds in tasks) per_specialist = {}for skill, seconds in tasks:    per_specialist[skill] = per_specialist.get(skill, 0) + secondsteam_time = max(per_specialist.values()) print("One agent does all tasks in sequence:", single_agent_time, "seconds")print("Three specialists work in parallel:  ", team_time, "seconds", per_specialist)print("Coordination is not free: the team also needs messages, shared context and a way to merge results.")
EXPECTED OUTPUT (your numbers may differ slightly)
Generalist prompt: 1160 tokens on every model call
researcher prompt: 570 tokens | 2 tools
analyst prompt: 640 tokens | 2 tools
assistant prompt: 550 tokens | 2 tools
One agent does all tasks in sequence: 18 seconds
Three specialists work in parallel: 8 seconds {'researcher': 8, 'analyst': 7, 'assistant': 3}
Coordination is not free: the team also needs messages, shared context and a way to merge results.

Each specialist carries about half the prompt of the generalist, and the team finishes in 8 seconds instead of 18. The last line is the catch: coordination is not free, which is why the later lessons cover communication, architectures and orchestration.

Knowledge Check

Question 1: When is a single agent usually the better choice?
Question 2: Which is a real cost of multi-agent systems?

Key Points

✓A multi-agent system splits work among agents with their own roles, tools and instructions.
✓Specialists have smaller prompts, pick tools better and can work in parallel.
✓A single agent is simpler, cheaper and easier to debug. Start there.
✓Add agents only when one agent fails from too many tools, too long a prompt or lack of parallelism.
✓Hidden costs: coordination, duplicated context, error compounding, conflicts and harder debugging.
✓Avoid over-splitting into many overlapping agents.

The Big Picture

Multi-Agent in One Line

Split by skill → keep each agent small → run independent work in parallel → pay the coordination cost

The art of multi-agent design is deciding how few agents you really need.

Up Next: Agents on a team must talk to each other. In Agent Communication and Collaboration you will learn message passing, shared context and collaborative problem solving.