Building Multi-Agent AI Systems: Patterns for Delegation and Collaboration

Published by

on

Multi-agent orchestrator connected to three worker nodes each with agents handling processing, simulation, optimization, decision making, resource management, monitoring, and security

I had a single agent that handled store operations questions. It worked well — until it didn’t. A store manager asked: “Check which products are expiring this week, find alternatives from our supplier catalog, and draft a reorder suggestion for my regional manager.”

The agent tried. It called the expiry tool, got 23 products, attempted to search the supplier catalog for each one, lost track of which products it had already processed, exceeded its context window, and returned a half-finished answer after 45 seconds and 60+ API calls.

The problem wasn’t the model. The problem was that I’d given one agent a job that needed three specialists: one to find expiring products, one to search supplier alternatives, and one to draft the recommendation. Each with its own tools, its own context, and its own focused task.

That’s when I started building multi-agent systems — and discovered that the patterns are simpler than the frameworks make them look.

Related: This post builds on What Is an AI Agent? and Function Calling & Tool Use. You’ll want to understand the single-agent loop before going multi.


Why One Agent Isn’t Enough

A single agent works well when:

  • The task requires 3-8 tool calls
  • All tools share the same domain context
  • The reasoning chain is linear

It breaks down when:

  • The task spans multiple domains. Checking inventory, searching a supplier catalog, and drafting an email are three different skill sets. One agent juggling all three loses focus.
  • The context window fills up. An agent that makes 40+ tool calls accumulates so much conversation history that the model starts losing track of earlier results.
  • Different steps need different models. A fast, cheap model can handle data lookups. The expensive reasoning model should only handle the final synthesis.
  • You need parallelism. A single agent processes sequentially. Three agents can work in parallel on independent subtasks.

The solution: decompose the task across multiple specialized agents, each with a narrow focus and a limited set of tools.


The Four Multi-Agent Patterns

After building several multi-agent systems, I’ve found that every design maps to one of four patterns. You don’t need a framework to implement any of them.

Pattern 1: Orchestrator-Worker

One agent (the orchestrator) breaks down the task and delegates subtasks to specialized worker agents. The orchestrator collects results and synthesizes the final answer.

User: "Find expiring products and suggest reorders"
│
▼
┌─────────────────────┐
│ ORCHESTRATOR │
│ "I need to: │
│ 1. Find expiring │
│ 2. Find suppliers │
│ 3. Draft email" │
└───┬────────┬────────┘
│ │ │
▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐
│Expiry │ │Supplier│ │Draft │
│Agent │ │Agent │ │Agent │
│ │ │ │ │ │
│Tools: │ │Tools: │ │Tools: │
│-expiry │ │-catalog│ │-email │
│-stock │ │-pricing│ │-template│
└───┬────┘ └───┬────┘ └───┬────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────┐
│ ORCHESTRATOR combines │
│ results into final answer │
└─────────────────────────────┘

This is the pattern I use most. The orchestrator is a lightweight agent — its only “tools” are the other agents. Each worker has a narrow scope and a small, focused toolset.

Here’s a minimal implementation:

import anthropic
import json
import asyncio
client = anthropic.Anthropic()
def run_agent(system_prompt: str, task: str, tools: list) -> str:
"""Run a single-purpose agent to completion."""
messages = [{"role": "user", "content": task}]
while True:
response = client.messages.create(
model="claude-sonnet-4-6-20250514",
max_tokens=4096,
system=system_prompt,
messages=messages,
tools=tools
)
# Check if the agent wants to use tools
tool_uses = [b for b in response.content if b.type == "tool_use"]
if not tool_uses:
# Agent is done — return the text response
return "".join(b.text for b in response.content if b.type == "text")
# Execute tool calls and feed results back
messages.append({"role": "assistant", "content": response.content})
tool_results = []
for tool_use in tool_uses:
result = execute_tool(tool_use.name, tool_use.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": tool_use.id,
"content": json.dumps(result)
})
messages.append({"role": "user", "content": tool_results})
async def orchestrate(user_request: str) -> str:
"""Orchestrator that delegates to specialized agents."""
# Step 1: Let the orchestrator decompose the task
plan = client.messages.create(
model="claude-sonnet-4-6-20250514",
max_tokens=1024,
system="You are a task planner. Break the user's request into independent subtasks. Return a JSON array of subtask descriptions.",
messages=[{"role": "user", "content": user_request}]
)
subtasks = json.loads(plan.content[0].text)
# Step 2: Run worker agents in parallel
workers = {
"inventory": (INVENTORY_SYSTEM_PROMPT, inventory_tools),
"supplier": (SUPPLIER_SYSTEM_PROMPT, supplier_tools),
"comms": (COMMS_SYSTEM_PROMPT, comms_tools),
}
results = await asyncio.gather(*[
asyncio.to_thread(
run_agent,
workers[task["agent"]][0], # system prompt
task["description"], # task
workers[task["agent"]][1], # tools
)
for task in subtasks
])
# Step 3: Synthesize
synthesis = client.messages.create(
model="claude-sonnet-4-6-20250514",
max_tokens=2048,
system="Combine these agent results into a single coherent response.",
messages=[{"role": "user", "content": json.dumps(dict(zip(
[t["description"] for t in subtasks], results
)))}]
)
return synthesis.content[0].text

The orchestrator makes three decisions: what subtasks to create, which agent handles each one, and how to combine the results. Everything else is handled by the workers.

Pattern 2: Handoff (Sequential Pipeline)

Agents pass work to each other in a chain. Each agent completes its task and hands the result to the next agent. Unlike orchestrator-worker, there’s no central coordinator — each agent decides when to hand off.

User request
│
▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Triage │────▶│ Research │────▶│ Response │
│ Agent │ │ Agent │ │ Agent │
│ │ │ │ │ │
│ Decides │ │ Looks up │ │ Drafts │
│ category │ │ context │ │ answer │
└──────────┘ └──────────┘ └──────────┘

This works well for customer support flows. A triage agent classifies the request, a research agent pulls the relevant data, and a response agent drafts the reply.

def handoff_chain(user_message: str) -> str:
# Agent 1: Triage
triage_result = run_agent(
system_prompt="Classify this message into: [billing, technical, general]. Return only the category.",
task=user_message,
tools=[]
)
# Agent 2: Research (gets different tools based on category)
research_tools = get_tools_for_category(triage_result.strip())
research_result = run_agent(
system_prompt=f"You handle {triage_result} requests. Look up all relevant information to answer the customer's question.",
task=user_message,
tools=research_tools
)
# Agent 3: Response
response = run_agent(
system_prompt="You are a customer service writer. Draft a helpful response using the research provided. Be concise and empathetic.",
task=f"Customer message: {user_message}\n\nResearch: {research_result}",
tools=[]
)
return response

The advantage: each agent has a minimal context. The triage agent doesn’t need to know about billing APIs. The response agent doesn’t need raw database results — just the processed research.

Pattern 3: Debate / Verifier

Two agents with different perspectives evaluate the same problem. A third agent resolves disagreements. This is useful when accuracy matters more than speed.

def verified_analysis(question: str) -> str:
# Two agents analyze independently
analysis_a = run_agent(
system_prompt="You are a cautious analyst. Identify risks and potential issues.",
task=question,
tools=analysis_tools
)
analysis_b = run_agent(
system_prompt="You are an optimistic analyst. Identify opportunities and positive signals.",
task=question,
tools=analysis_tools
)
# Verifier reconciles
final = run_agent(
system_prompt="You are a senior reviewer. Two analysts have provided different perspectives. Identify where they agree, where they disagree, and provide your final assessment.",
task=f"Analysis A (risk-focused):\n{analysis_a}\n\nAnalysis B (opportunity-focused):\n{analysis_b}",
tools=[]
)
return final

I used this pattern for a product markdown recommendation system. One agent aggressively suggested markdowns to minimize waste. Another conservatively protected margins. A third balanced both perspectives. The combined recommendation was consistently better than either agent alone.

Pattern 4: Autonomous Swarm

Multiple agents operate independently with a shared message bus or state. No orchestrator. Each agent watches for tasks it can handle and picks them up. This is the most complex pattern and the one I’d recommend least for most teams.

I’m mentioning it for completeness, but I haven’t used it in production. The coordination overhead (conflict resolution, duplicate work, deadlocks) outweighed the benefits for every use case I evaluated. If you think you need a swarm, you probably need an orchestrator with more workers.


Agent Communication: The Practical Details

The biggest design decision isn’t which pattern to use — it’s how agents pass information to each other. I’ve tried three approaches.

Option 1: String Passing (Start Here)

The simplest approach: each agent returns a string, and the next agent receives it as input.

result_a = run_agent("Find expiring products", ...)
result_b = run_agent(f"Given these products: {result_a}, find suppliers", ...)

Pros: dead simple, easy to debug, works today. Cons: no structure, downstream agents have to parse natural language.

Option 2: Structured Handoff Objects

Each agent returns a typed object. Downstream agents receive structured data.

@dataclass
class HandoffPayload:
summary: str # Human-readable summary
data: dict # Structured data for the next agent
confidence: float # How confident this agent is in its result
needs_review: bool # Flag for human-in-the-loop
# Agent returns structured output
expiry_result = HandoffPayload(
summary="Found 6 products expiring within 48 hours with stock > 10 units",
data={"products": [{"spar_nummer": 45678, "stock": 23, "expiry": "2025-03-15"}, ...]},
confidence=0.95,
needs_review=False
)

This is what I use in production. The summary field goes to the next agent’s prompt. The data field is available for programmatic processing. The confidence and needs_review fields trigger human escalation when needed.

Option 3: Shared State (Database/Cache)

Agents read and write to a shared store. Each agent can access any previous agent’s results by key.

state = AgentState(session_id="abc123")
# Agent 1 writes
state.set("expiring_products", [...])
# Agent 2 reads
products = state.get("expiring_products")

This works well for long-running workflows where agents may run hours apart. For real-time multi-agent interactions, string passing or structured handoffs are simpler and sufficient.


What Didn’t Work: Honest Failures

Agents That Talk To Each Other Directly

My first attempt: let agents call each other as tools. Agent A could “call” Agent B by invoking a tool, Agent B would run, and its result would come back as a tool result.

It was a disaster. Agent A would call Agent B with vague instructions. Agent B would ask clarifying questions (returned as text, not as a real question). Agent A would interpret B’s question as a final answer. The result was nonsense presented confidently.

Lesson: Agents should communicate through structured data, not freeform conversation. An orchestrator that explicitly defines what each agent should do produces far better results than agents negotiating with each other.

Over-Specialization

I built a system with 8 specialized agents. One just fetched stock. One just fetched prices. One just fetched promotions. The orchestrator spent more time routing than the workers spent working. Three API calls that a single agent handled in 2 seconds took the multi-agent system 12 seconds because of the routing overhead.

Lesson: Use multiple agents when tasks are genuinely independent and complex. If a task is “call three APIs and combine the results,” that’s one agent with three tools — not three agents with one tool each.

No Timeout, No Budget

An orchestrator spawned a worker that got stuck in a retry loop. The worker kept calling an API that returned errors, reasoning that it should try a different query. It burned through 200K tokens before I noticed.

Lesson: Every agent needs a hard limit — max steps, max tokens, max wall-clock time. My defaults: 15 steps, 50K tokens, 30 seconds. The agent must return its best partial answer when it hits any limit.

MAX_STEPS = 15
MAX_TOKENS = 50_000
tokens_used = 0
for step in range(MAX_STEPS):
response = client.messages.create(...)
tokens_used += response.usage.input_tokens + response.usage.output_tokens
if tokens_used > MAX_TOKENS:
return "Budget exceeded. Partial result: " + collect_partial_results()
if not has_tool_calls(response):
return extract_text(response)
return "Step limit reached. Partial result: " + collect_partial_results()

When to Use Multi-Agent vs. Single Agent

ScenarioUse Single AgentUse Multi-Agent
3-8 tool calls, one domainYesOverkill
15+ tool calls, mixed domainsStrugglesYes — orchestrator-worker
Sequential workflow with clear stagesCould workYes — handoff chain
Accuracy-critical decisionsRiskyYes — debate/verifier
Simple Q&A with data lookupYesOverkill
Tasks requiring different model tiersNoYes — cheap model for lookup, expensive for synthesis

My rule of thumb: start with one agent. Split only when you see it struggling — losing context, calling wrong tools, or taking too long. Don’t design for multi-agent upfront. You’ll almost certainly split along the wrong boundaries.


Cost and Latency: The Real Numbers

Multi-agent systems multiply your API costs. Every agent is a separate LLM conversation. Here’s a real comparison from my store operations system:

MetricSingle AgentOrchestrator + 3 Workers
Total tokens~15K~35K
API calls1 conversation5 conversations (orchestrator + plan + 3 workers + synthesis)
Latency (sequential)~8s~14s
Latency (parallel workers)~8s~9s
Cost (Claude Sonnet)~$0.05~$0.12
Accuracy on complex tasks~70%~90%

The cost is 2-3x higher. The latency is comparable if you parallelize workers. The accuracy improvement on complex tasks justified the cost for my use case. For simple tasks, the single agent was both cheaper and faster.

Cost optimization tip: Use a cheap, fast model (Haiku) for the orchestrator’s planning step and for simple worker tasks. Reserve the expensive model (Sonnet/Opus) for the final synthesis and for workers doing complex reasoning.


Final Thoughts: Agents Are a Team, Not a Committee

The best multi-agent systems look like well-run teams: clear roles, minimal meetings, structured handoffs. The worst ones look like committees: endless back-and-forth, unclear ownership, and a result that nobody’s happy with.

Three principles that kept my systems simple:

  1. Each agent owns one outcome. If you can’t describe what the agent does in one sentence, it’s doing too much.
  2. Communication is data, not conversation. Agents pass structured results, not chat messages.
  3. The orchestrator is thin. It plans and delegates. It doesn’t do the work. If your orchestrator has 10 tools, it’s not an orchestrator — it’s a overloaded single agent with extra steps.

Start with one agent. Let it fail at complex tasks. Then split along the natural fault lines — the places where context, tools, and domain expertise diverge. That’s where multi-agent systems earn their complexity.


Previously: Function Calling & Tool Use: I Gave an LLM Access to My APIs. Next: Loop Engineering

One response to “Building Multi-Agent AI Systems: Patterns for Delegation and Collaboration”

  1. […] Previously: What Is an AI Agent?. Next: Multi-Agent Systems: How I Built AI Agents That Delegate, Retry, and Collaborate. […]

Leave a Reply