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.
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
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.
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.
Chapter 1
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:
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).
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.
T-par equals the max of t-one through t-k.
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 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.
Chapter 2
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.
| Style | When it thinks | Reported result |
|---|---|---|
| ReAct | before each action: thought, action, observation, repeat | beat 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-execute | once: write the plan, run the steps, then answer | ReWOO: 5× token efficiency and 4% higher accuracy on HotpotQA (Xu et al., 2023) |
| Reflexion | after a failed try: write a lesson in words, keep it, try again | 91% 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.
T-ReAct equals n plus one, times P, plus o times n times n plus one, over two.
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 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.
Pick a style to see its trace. Drag the steps and watch the grey token bars.
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.
Chapter 3
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.
M equals R times thirty times T times m.
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 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.
Each grey bar is one design's monthly bill. Pick a design and drag the volume.
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.
Chapter 4
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.
P-run equals p to the n.
Multiply the step chance p by itself n times, once per step. The product is P-run.
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.
The purple curve is the chance of a good run against the number of steps. The faint curve is p = 0.99 for reference.
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:
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.
Chapter 5
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.
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.
| Workflow | Agent | |
|---|---|---|
| Path | fixed in code, same every run | chosen by the model, can differ |
| Cost per run | known before it runs | known only on average |
| Audit | read the code | read the trace of each run |
| An unplanned case | no branch, so it fails | it 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.
Chapter 6
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.
| Pattern | Shape | Use when | Example from the source |
|---|---|---|---|
| Prompt chaining | A, then B, then C; each call reads the last output | the task splits into fixed steps | write an outline, check it, then write the document |
| Routing | classify, then send to one handler | inputs fall into distinct groups | easy questions to a small model, hard ones to a large one |
| Parallelization | fan out, merge in code | parts are independent (sectioning), or you want several votes (voting) | several prompts review code for vulnerabilities |
| Orchestrator-workers | a central model splits the task, workers do parts, it merges | you cannot predict the subtasks | a coding change across many files |
| Evaluator-optimizer | generate, evaluate, revise, in a loop | criteria are clear and revision helps | literary 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."
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.
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.
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 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.
Pink bars are majority accuracy for 1 to 9 voters. Raise "same mistakes" and watch the gain shrink.
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.
Chapter 7
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.
Pick a shape and press Run. Each moving dot is one message. Drag the number of agents.
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:
M-peer equals n times n minus one.
Each of the n agents sends one message to each of the other n − 1. Multiply. A supervisor needs only 2 × n.
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.
Chapter 8
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.
Change any answer. The drawing, the reasons and the token multiple update at once.
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.
Chapter 9
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.
k equals the floor of W minus B, over r.
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 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.
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.
Chapter 10
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.
| Term | Meaning | Number from this lesson |
|---|---|---|
| Agent loop | decide, act, observe, repeat | parallel: 4 s instead of 5.5 s |
| ReAct | think before every action | 12,500 tokens at n = 4 |
| Plan-and-execute | plan once, run, answer | 5,000 tokens at n = 4 |
| Reflexion | a lesson in words after a failed try | 91% pass@1 on HumanEval |
| Token multiplier | tokens against one chat answer | agent about 4×, team about 15× |
| Compounding errors | p to the n | 0.9520 = 0.36 |
| Voting | majority of independent voters | p = 0.8, k = 3: 0.896 |
| Peer messages | n(n − 1) per round | n = 8: 56 against 16 |
| Context budget | calls that fit the window | 3 calls raw, 7 capped |
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]
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.
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.