Multi-Agent Patterns

Several Agents Working Together

A multi-agent system splits work across several model calls with different prompts, tools or models. Each agent has a small, focused job and its own context window.

PatternHow it worksGood for
Orchestrator-workersa lead agent plans and hands sub-tasks to worker agentsresearch, large catalogue jobs
Pipelineagent A → agent B → agent C, fixed orderextract → enrich → write
Generator-criticone agent writes, another reviews and sends feedbackcontent quality, code review
Router + specialistsa router sends each request to one expert agentsupport desks with many topics

Example

Example

Orchestrator-workers with a critic. Every "agent" is a stand-in function so the flow is visible; in real code each one is a model call with its own system prompt.

def orchestrator(task):           # stand-in: plans sub-tasks
    return ["write title", "write 3 bullet features", "write care instructions"]

def worker(subtask, product):     # stand-in: does one sub-task
    return {"write title": f"{product} - 3L, Induction Base",
            "write 3 bullet features": "- 5-year warranty\n- ISI marked\n- Works on gas and induction",
            "write care instructions": "Hand wash. Do not use steel wool."}[subtask]

def critic(text):                 # stand-in: checks brand rules
    problems = []
    if "guaranteed" in text.lower(): problems.append("no 'guaranteed' claims")
    if len(text) > 400: problems.append("too long")
    return problems or ["ok"]

product = "Prestige Svachh Pressure Cooker"
plan = orchestrator(f"Product page for {product}")
parts = [worker(s, product) for s in plan]
page = "\n".join(parts)
print("plan:", plan)
print(page)
print("critic:", critic(page))

Output

plan: ['write title', 'write 3 bullet features', 'write care instructions']
Prestige Svachh Pressure Cooker - 3L, Induction Base
- 5-year warranty
- ISI marked
- Works on gas and induction
Hand wash. Do not use steel wool.
critic: ['ok']

LangGraph

Frameworks like LangGraph describe multi-step and multi-agent flows as a graph of nodes that share a state object. Learn the raw loop first; use a framework when the graph grows.

from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    question: str
    docs: list[str]
    answer: str

def retrieve(state: State):
    return {"docs": search_policies(state["question"])}

def answer(state: State):
    return {"answer": ask_claude(state["question"], state["docs"])}

builder = StateGraph(State)
builder.add_node("retrieve", retrieve)
builder.add_node("answer", answer)
builder.add_edge(START, "retrieve")
builder.add_edge("retrieve", "answer")
builder.add_edge("answer", END)
graph = builder.compile()
print(graph.invoke({"question": "What is the return window?"})["answer"])

Note

Note: Multi-agent systems use many more tokens than one agent, and errors can pass from one agent to the next. Use them when the task really splits into independent parts, and measure the gain with evals.