Agent Architectures

A single agent reads about 4 times the tokens of a chat answer. A team of agents reads about 15 times. Pick the simplest design that solves the task.

Pick a task, then pick a design. Watch whether it fails, fits or overpays. Then we build each design, piece by piece: the loop, its styles, the workflow patterns, the teams, and a chooser.

You need to know what a language model is and a little Python. We build the rest from zero.

Built on Anthropic's Building effective agents (Schluntz and Zhang, 2024) and How we built our multi-agent research system (2025), with ReAct, Reflexion and plan-and-execute from their papers. Part of the Harness family with Harness Engineering and Agent Skills.

Match the design to the task

Tokens are relative to one chat answer. The 4× for an agent and 15× for a multi-agent system are Anthropic's measurements (2025). The 3× for a three-call workflow is our assumption. The verdicts follow this lesson's rules and are illustrative.

Chapter 0

A Script Breaks, an Agent Adapts

See what an agent does that a fixed script cannot, and what that freedom costs

A ticket arrives: "My March invoice charged me twice." A script handles it in three fixed steps. Look up the account. Fetch the March invoices. Refund the duplicate. It is fast, cheap and easy to audit.

Today the billing database times out at step 2. The script has no step for that. It stops, and the ticket waits for a person.

An agent is a model that runs in a loop, picks its own next step, and uses tools to act. It reads the timeout. It checks the payment provider's records instead, finds the duplicate charge and refunds it.

Break step 2

Warm arrows are a path your code fixed in advance. Purple arrows are steps the model chose. Pick a mode and press Run.

Illustrative toy. We made up the ticket, the timeout and the backup source.

Anthropic draws the line in one pair of definitions (Schluntz and Zhang, 2024). A workflow is a system where "LLMs and tools are orchestrated through predefined code paths." An agent is a system where "LLMs dynamically direct their own processes and tool usage." The difference is not model size. It is who decides the next step.

With made-up numbers: 1,000 tickets a day, and 4% hit a case the script has no branch for. That is 40 tickets a day that wait for a person. An agent that recovers half of them saves 20.

The failure. The symptom: an agent where a script would do. The bill grows, and two runs of the same ticket take different paths. To measure it, count how often the agent's path differs from the obvious script. If it almost never differs, you pay for freedom you do not use. The fix: write the script, and send only its failures to an agent.

The road

  1. The agent loop: decide, act, observe, and parallel tool calls.
  2. Three loop styles: ReAct, plan-and-execute and Reflexion, and what each costs.
  3. Price each rung: tokens per month for each design. Hero: the token bars.
  4. Where one agent breaks: compounding errors and distractor domains.
  5. Workflow or agent: who draws the arrows. Hero: the workflow and agent buttons.
  6. Five workflow patterns: chain, route, parallel, orchestrate, evaluate.
  7. Many agents: a supervisor or peers. Hero: the multi-agent button.
  8. The chooser: answer five questions, get the simplest design.
  9. Context and traces: keep the window small and the run visible.
  10. Field guide: terms, numbers, a checklist, the code and the sources.
What separates an agent from a fixed script?

Chapter 1

The Agent Loop

Run one research task through decide, act and observe, and see what parallel tool calls save

You ask a research agent: "Which code-review tools do teams adopt, and does adoption match our own review times?" Memory cannot answer that. The agent needs the web and your database.

Every agent runs one loop:

  1. Decide. The model reads the context and picks the next action.
  2. Act. The harness runs the tool the model asked for.
  3. Observe. The tool's result goes back into the context.
  4. Repeat until the model says it is done, or a limit stops it.

Four parts make the loop. The model decides. The prompt gives the role, the tools and when to stop. The tools act on the world: a web search, a SQL query. Skills are optional folders of instructions the agent loads when a task needs them (Agent Skills).

Step the loop

Each press runs one beat. Blue bars are tool calls on a time line. Switch parallel calls on and off and step again.

Illustrative times: web search 4 s, SQL query 1.5 s, follow-up search 2.5 s, 1 s per model turn.

In beat 2 the model sees that the search and the query do not depend on each other. So it asks for both in one turn: a parallel tool call. What does that save?

Call the time of tool call number i ti, and the number of independent calls k. Run them one after another and you wait for the sum. Run them at once and you wait for the slowest.

Say it aloud

T-par equals the max of t-one through t-k.

Tpar
T-par the wait for all k calls when they run at the same time, in seconds.
max
the max of the largest value in the list.
t1 … tk
t-one through t-k the time of each of the k calls that do not depend on each other.
In plain words

List the time t-i of each independent call. The slowest one sets T-par. The serial wait is the sum of all the t-i.

With numbers

With made-up numbers: search t-1 = 4 s, query t-2 = 1.5 s. Serial: 5.5 s. Parallel: T-par = max(4, 1.5) = 4 s. Add a third call of 2.5 s: serial grows to 8 s, T-par stays 4 s.

Anthropic's research system runs subagents in parallel, and each subagent calls tools in parallel. The team reports that these two changes cut research time by up to 90% on complex queries (2025).

The failure. The symptom: an agent takes twice as long as it should. To measure it, find calls in the trace that share no data but ran in separate turns. The fix: tell the model that independent calls go in one turn, and make the harness run them at the same time.

An agent makes three independent tool calls of 3 s, 2 s and 6 s in one turn. How long does it wait?

Chapter 2

Three Ways to Run the Loop

Compare ReAct, plan-and-execute and Reflexion by when the model thinks and how many tokens it reads

The loop leaves one choice open. When does the model think: before every action, once at the start, or after a failed try? Three published styles answer differently.

StyleWhen it thinksReported result
ReActbefore each action: thought, action, observation, repeatbeat imitation and RL methods by 34 and 10 points of absolute success on ALFWorld and WebShop, from one or two examples (Yao et al., 2022)
Plan-and-executeonce: write the plan, run the steps, then answerReWOO: 5× token efficiency and 4% higher accuracy on HotpotQA (Xu et al., 2023)
Reflexionafter a failed try: write a lesson in words, keep it, try again91% pass@1 on HumanEval (Shinn et al., 2023)

Why does ReAct read more tokens? Each model call reads everything so far. Call the fixed prompt P tokens, each tool result o tokens, and the number of tool steps n. ReAct makes n + 1 model calls, and call number i reads P plus i results.

Say it aloud

T-ReAct equals n plus one, times P, plus o times n times n plus one, over two.

TReAct
T-ReAct the total tokens the model reads over the whole task.
n + 1
n plus one the number of model calls: one before each of the n tool steps, plus one to answer.
P
P the prompt every call reads: instructions, tool list, the task.
o
o the tokens in one tool result.
n(n + 1)/2
n times n plus one, over two how many results get read in total: 0 + 1 + 2 + … + n.
In plain words

Each of the n + 1 calls reads the prompt P. Call i also reads the i results so far. Add up the results read, n(n + 1)/2 of them, at o tokens each.

With numbers

With made-up numbers: P = 1,500, o = 500, n = 4. T-ReAct = 5 × 1,500 + 500 × 10 = 12,500 tokens. Plan-and-execute reads P once to plan, then P plus 4 results once to answer: 1,500 + 3,500 = 5,000 tokens.

Grow the task, compare the styles

Pick a style to see its trace. Drag the steps and watch the grey token bars.

4

Illustrative: P = 1,500 and o = 500 tokens. Reflexion here is one failed ReAct try, then one reflection call that reads the prompt and the failed results. A second ReAct try follows, and each of its calls also reads the 300-token lesson.

The trade: plan-and-execute grows in a straight line with n, but it cannot change the plan when step 2 returns a surprise. ReAct re-decides at every step, so it adapts, and its cost grows with n squared. Reflexion pays for a whole second try, so use it when a test can tell you a try failed.

The failure. The symptom: a plan-and-execute agent runs every step and answers wrong, because step 2 returned an error. To measure it, count runs where one result made the later steps pointless. The fix: replan when a result fails a check, or move that task to ReAct.

A task needs 8 tool steps, and the plan rarely changes. Which style reads the fewest tokens?

Chapter 3

Start Simple: Price Each Rung

Turn requests per day into tokens per month for each design, and see why the simplest design wins by default

Building effective agents gives one rule above the rest: "we recommend finding the simplest solution possible, and only increasing complexity when needed." Each rung up costs tokens. How many?

Anthropic measured it on its own products (2025): "agents typically use about 4× more tokens than chat interactions, and multi-agent systems use about 15× more tokens than chats."

Call the requests per day R, the tokens in one plain chat answer T, and the design's multiplier m. A month has about 30 days.

Say it aloud

M equals R times thirty times T times m.

M
M the tokens you pay for in one month.
R
R the requests per day.
30
thirty days in a month.
T
T the tokens in one plain chat answer.
m
m the design's multiplier: 1 for a chat, about 4 for an agent, about 15 for a multi-agent system.
In plain words

Multiply the requests per day R by 30 days. Multiply by T, the tokens of one chat answer. Multiply by the design's multiplier m. That is M.

With numbers

With made-up R and T and Anthropic's multipliers: R = 10,000 and T = 1,500. Chat: M = 450 million. Agent, m = 4: 1.8 billion. Multi-agent, m = 15: 6.75 billion. At an illustrative $3 per million tokens: $1,350, $5,400 and $20,250 a month.

Price the month

Each grey bar is one design's monthly bill. Pick a design and drag the volume.

10,000
$3.0

T = 1,500 tokens and the prices are illustrative. Multipliers 4 and 15 are Anthropic's (2025); 3 for a three-call workflow is our assumption.

Model choice is the second lever. A small fast model can tag tickets as well as a large one, for less. Anthropic's research system puts a larger model (Claude Opus 4) in the lead and a smaller one (Claude Sonnet 4) in each subagent.

The failure. The symptom: the bill grows faster than the traffic. To measure it, log tokens per request, split by design path. The fix: send easy requests to a single call and keep the agent path for the rest. Chapter 6 calls this routing.

2,000 requests a day, 1,500 chat tokens each, on a single agent (m = 4). About how many tokens a month?

Chapter 4

Where One Agent Breaks

See how small errors per step add up over a long run, and how unrelated domains crowd one context

A single agent is the right default. Two things break it: long chains of steps, and too many domains in one context.

Long chains. Building effective agents warns that autonomy brings "the potential for compounding errors." Here is why. Call the chance that one step goes right p, and the number of steps n. Say one bad step ruins the run, and steps fail independently. Then the run succeeds only if every step does.

Say it aloud

P-run equals p to the n.

Prun
P-run the chance the whole run goes right, from 0 to 1.
p
p the chance one step goes right.
n
to the n multiply p by itself once for each of the n steps.
In plain words

Multiply the step chance p by itself n times, once per step. The product is P-run.

With numbers

With made-up numbers: p = 0.95 and n = 20 give P-run = 0.9520 = 0.36. Raise p to 0.99 and P-run = 0.82. A small gain per step is a big gain per run.

Lengthen the chain

The purple curve is the chance of a good run against the number of steps. The faint curve is p = 0.99 for reference.

0.950
20

A worst-case toy: every error is fatal and errors are independent. Real agents catch some errors when a test fails or a tool returns a message, and retry.

That is why checks inside the loop matter. An error the agent sees is an error it can fix.

Too many domains. LangChain (2025) gave one gpt-4o agent the retail tasks of τ-bench. Then they added unrelated domains, each with 19 tools and its own instructions. They report that "the single agent baseline falls off sharply when there are two or more distractor domains." The other domains' tools crowd the context.

So climb in this order, and measure at each rung:

  1. A single agent.
  2. The same agent with Skills, so each domain's instructions load only when needed.
  3. Many agents, each owning one domain or one direction (Chapter 7).

The failure. The symptom: accuracy drops on old tasks after you add tools for a new domain. To measure it, rerun the old eval set with and without the new tools. The fix: load the new domain on demand, or give it its own agent.

Each step goes right 90% of the time and one bad step ruins the run. About what share of 10-step runs succeed?

Chapter 5

Workflow or Agent: Who Draws the Arrows

Run a fixed workflow and an agent on the same ticket several times, and trade control for flexibility

Every design in this lesson answers one question: who decides the next step, your code or the model?

In a workflow, your code draws the arrows. The model fills each box. In an agent, the model draws the arrows while it runs. Nobody drew them in advance.

Run it three times

Press Run a few times in each mode. The workflow repeats one warm path. The agent picks a purple path each run.

Illustrative toy. The agent's three paths come from a fixed list so every reader sees the same runs.

WorkflowAgent
Pathfixed in code, same every runchosen by the model, can differ
Cost per runknown before it runsknown only on average
Auditread the coderead the trace of each run
An unplanned caseno branch, so it failsit can try another way

With the device's runs: the workflow makes 3 model calls every time. The agent made 3, 5 and 4 calls on three runs of the same ticket. You can price the workflow before it runs. You can price the agent only on average.

A workflow can still let the model choose at one point. A router call picks which branch runs. The shape stays yours; one choice is the model's. This mix is common.

The failure. The symptom: a workflow fails on 1 input in 20 because no branch fits. To measure it, log every input that reaches the fallback branch. The fix: add a branch if the cases repeat, and hand the rest to an agent.

What one question separates a workflow from an agent?

Chapter 6

Five Workflow Patterns

Step through the five fixed shapes of model calls, and compute what voting buys

Building effective agents names five workflow patterns. Each is a fixed shape of model calls.

PatternShapeUse whenExample from the source
Prompt chainingA, then B, then C; each call reads the last outputthe task splits into fixed stepswrite an outline, check it, then write the document
Routingclassify, then send to one handlerinputs fall into distinct groupseasy questions to a small model, hard ones to a large one
Parallelizationfan out, merge in codeparts are independent (sectioning), or you want several votes (voting)several prompts review code for vulnerabilities
Orchestrator-workersa central model splits the task, workers do parts, it mergesyou cannot predict the subtasksa coding change across many files
Evaluator-optimizergenerate, evaluate, revise, in a loopcriteria are clear and revision helpsliterary translation

Chaining's goal, in the source's words, is to "trade off latency for higher accuracy, by making each LLM call an easier task."

Step through a pattern

Pick a pattern and press Step. Purple boxes are model calls; warm arrows are fixed by your code; pink is a check.

Shapes follow Building effective agents (2024). The example requests are ours.

Voting has a simple formula. Call the chance one voter is right p and the odd number of voters k. Assume the voters make their mistakes independently. The majority is right when more than half are right.

Say it aloud

P-maj equals the sum over j greater than k over two, of k choose j, times p to the j, times one minus p to the k minus j.

Pmaj
P-maj the chance the majority vote is right.
Σj > k/2
the sum over j greater than k over two add one term for each winning count j of right voters, from just over half up to all k.
C(k, j)
k choose j the number of ways to pick which j of the k voters are right.
pj
p to the j the chance those j voters are all right.
(1 − p)k − j
one minus p to the k minus j the chance the other k minus j voters are all wrong.
In plain words

For each winning count j, count the ways C(k, j) to pick the right voters. Multiply by the chance those j are right and the other k − j are wrong. Add the terms.

With numbers

With made-up numbers: p = 0.8 and k = 3. Two right: 3 × 0.64 × 0.2 = 0.384. Three right: 0.512. P-maj = 0.896. Five voters give 0.942.

Add voters

Pink bars are majority accuracy for 1 to 9 voters. Raise "same mistakes" and watch the gain shrink.

0.80
0%

Illustrative model: with chance "same mistakes" all voters copy one draw, otherwise they vote independently.

The failure. The symptom: five voters and no gain. To measure it, count how often the voters agree when they are wrong. The fix: vary the prompts, as in the source's example, or vary the models.

You need accurate API docs, and a checker that compares them with the code finds real errors. Which pattern fits?

Chapter 7

Many Agents: a Supervisor or Peers

Split work across agents in two shapes, and count the messages each shape sends

When one agent has too much to hold, split the work across agents. There are two shapes.

In a supervisor system, one lead agent splits the task, sends parts to subagents, and merges their answers. The lead calls a subagent the way it calls a tool: a name, an input, a result. So the loop from Chapter 1 needs nothing new.

In a peer system, or swarm, agents talk to each other and hand off the conversation. They share a chat thread, or a blackboard: one store that every agent reads and writes.

Count the messages

Pick a shape and press Run. Each moving dot is one message. Drag the number of agents.

4

One round: the supervisor sends each worker a task and gets one result; each peer sends one message to every other peer.

How much talk does each shape need? Call the number of worker agents n. A supervisor sends each worker one task and gets one result back: 2 × n messages a round. When every peer messages every other peer:

Say it aloud

M-peer equals n times n minus one.

Mpeer
M-peer the messages in one round of a peer system.
n
n the number of agents.
n − 1
n minus one the other agents each one sends to.
In plain words

Each of the n agents sends one message to each of the other n − 1. Multiply. A supervisor needs only 2 × n.

With numbers

n = 4: peers send 12, the supervisor 8. n = 8: peers send 56, the supervisor 16. Every message is tokens that some agent must read.

Anthropic's research system is a supervisor shape. A lead agent on Claude Opus 4 runs subagents on Claude Sonnet 4 in parallel. It "outperformed single-agent Claude Opus 4 by 90.2%" on Anthropic's internal research eval. The same post warns about a poor fit: tasks where all agents need the same context, or with many dependencies. Most coding tasks have fewer parallel parts than research.

LangChain's τ-bench test (2025) found the swarm slightly ahead of the supervisor. The supervisor lost points to "translation": its subagents cannot answer the user directly.

The failure. The symptom: agents bounce a task back and forth, or two subagents run the same search. To measure it, count repeated tool calls and handoff loops in the traces. The fix: give each subagent one objective, an output format and clear limits, and cap the number of handoffs.

How does a supervisor agent call a specialist subagent?

Chapter 8

The Architecture Chooser

Answer five questions about a task and get the simplest design that fits, with its reasons and its price

Everything so far reduces to five questions. Answer them for your task, and the design mostly chooses itself. The chooser below applies the rules of Chapters 3 to 7 and draws the result.

Answer, and watch the design

Change any answer. The drawing, the reasons and the token multiple update at once.

Are the steps known in advance?
How many domains?
Independent directions to explore at once?
Must you explain every step to an auditor?
Budget?

The rules are this lesson's summary of the sources, not a law. Token multiples: 3× for a workflow is our assumption; 4× and 15× are Anthropic's.

Try three cases. Steps known, one domain: a chain, priced before it runs. Steps unknown, one domain, tight budget: a single agent. Steps unknown, independent directions, room to spend: a lead with parallel subagents, at about 15× a chat.

Real systems are often hybrids. Three common ones:

The failure. The symptom: a design picked for how impressive it is. To measure it, run the next rung down on the same eval set. If it scores the same, the extra rung is cost with no return. The fix: ship the lower rung, and keep the eval to tell you when to climb.

A loan-approval task has known steps, one domain, and every decision must be explained to a regulator. What does the chooser recommend?

Chapter 9

Keep the Context Small and the Run Visible

Budget the context window against tool results, and record every run so you can debug it

Every lap of the loop adds to the context: a thought, a tool call, a result. Results are the big ones. One unpaged database query can return tens of thousands of tokens. Then the window fills.

Anthropic ships three fixes (2025):

On an internal agentic search eval, context editing alone raised performance 29%; with the memory tool, 39%. In a 100-turn web search, context editing cut token use by 84%.

How many calls fit? Call the window size W, the base context B (system prompt and task), and the size of one tool result r.

Say it aloud

k equals the floor of W minus B, over r.

k
k the number of tool results that fit before the window is full.
⌊ ⌋
the floor of round down to a whole number, since a call cannot half fit.
W
W the window size, in tokens.
B
B the base context: system prompt and task.
r
r the tokens in one tool result.
In plain words

Take the window W. Subtract the base context B. Divide the room left by the result size r, and round down. That is k.

With numbers

With made-up numbers: W = 200,000, B = 20,000, r = 60,000. k = 3, and the window is exactly full. Cap r at 25,000: 180,000 / 25,000 = 7.2, so k = 7, using 195,000 tokens.

Fill the window

Each press adds one blue tool result. Switch on the fixes and keep going.

Illustrative: a 200,000-token window, 20,000 base tokens, raw results of 60,000. Our toy editing rule keeps only the newest 3 results once the window passes 80%.

The second fix is visibility. Two runs of the same input can take different paths, so rerunning a failure may not reproduce it. Record every run: the prompt, each model decision, each tool call and result, and the tokens. In a team, also record who sent what to whom.

The failure. The symptom: the agent forgets an early instruction late in a long run. To measure it, plot the context fill per turn in the trace. The fix: cap results at the tool, clear stale ones, and keep durable facts in memory files.

Why must you record agent traces before a failure, not after?

Chapter 10

Field Guide

Keep the terms, the numbers, a checklist, the code and the sources in one place

An agent is a model in a loop that picks its own next step. A workflow is a path your code fixes in advance. Start with the simplest design, measure it, and climb one rung only when the eval says the rung pays.

TermMeaningNumber from this lesson
Agent loopdecide, act, observe, repeatparallel: 4 s instead of 5.5 s
ReActthink before every action12,500 tokens at n = 4
Plan-and-executeplan once, run, answer5,000 tokens at n = 4
Reflexiona lesson in words after a failed try91% pass@1 on HumanEval
Token multipliertokens against one chat answeragent about 4×, team about 15×
Compounding errorsp to the n0.9520 = 0.36
Votingmajority of independent votersp = 0.8, k = 3: 0.896
Peer messagesn(n − 1) per roundn = 8: 56 against 16
Context budgetcalls that fit the window3 calls raw, 7 capped

Six questions before you build

  1. Can one call do it? Then stop. (Chapter 3)
  2. Are the steps known? Then use a workflow pattern. (Chapters 5 and 6)
  3. How long is the chain, and where are the checks? (Chapter 4)
  4. How many domains share one context? (Chapter 4)
  5. Are there independent directions worth 15× the tokens? (Chapters 3 and 7)
  6. Do you cap results and record every run? (Chapter 9)

The whole lesson as code

A single agent in about twenty lines. Every other design rearranges these parts.

pythondef run_agent(task, model, tools, max_turns=20, cap=25_000):
    context = [system_prompt(tools), task]                    # B: the base context
    trace = []                                                # Ch 9: record every run
    for turn in range(max_turns):                          # a hard limit ends the loop
        reply = model(context)                                # decide
        trace.append(reply)
        if not reply.tool_calls:                            # the model says it is done
            return reply.text, trace
        results = run_parallel(reply.tool_calls, tools)       # act: independent calls at once
        results = [truncate(r, cap) for r in results]          # cap each result
        context += [reply] + results                          # observe
        context = clear_stale(context)                        # context editing
    return "stopped: turn limit", trace

# a subagent is a tool: the supervisor calls it by name
def research_subagent(objective):
    return run_agent(objective, small_model, web_tools)[0]

Keep going

The takeaway. Pick the design by who must decide the next step, how many domains share a context, and what the task is worth. Start one rung lower than you think, and let the eval move you up.
A team jumps straight to a multi-agent system for a one-domain task with known steps. What is the first thing to try instead?

Now press Present or Teach and explain from memory: the loop, the three styles, the five patterns and the two team shapes. Then go back to the hero and say, for each task, which design fits and why.

Sources

E. Schluntz and B. Zhang, Building effective agents, Anthropic, 19 December 2024. J. Hadfield, B. Zhang, K. Lien, F. Scholz, J. Fox and D. Ford, How we built our multi-agent research system, Anthropic, 13 June 2025. S. Yao et al., ReAct (2022). N. Shinn et al., Reflexion (2023). L. Wang et al., Plan-and-Solve Prompting (2023). B. Xu et al., ReWOO (2023). LangChain, Benchmarking multi-agent architectures, 10 June 2025. Anthropic, Writing effective tools for agents, 11 September 2025, and Managing context on the Claude Developer Platform, 29 September 2025. The toy numbers and devices are ours.

Agent Architectures: Single Agents to Multi-Agent Orchestration
Read Building effective agents · Harness Engineering · Back to Gleams