Machinery Learning

Part 2: Agents · Chapter 1 of 5

From chat to agent: tools and the loop

An agent is a language model called again and again, with tools in between. Step through the loop and see why small mistakes add up and what each step costs.

About 12 minutesUpdated November 2026

After this chapter you can

  • Explain what turns a chat model into an agent
  • Say who carries out an action: the model, or the software around it
  • Explain why long tasks fail more often than their single steps suggest

Part 1 ended with a model that writes text, one token at a time. That model can’t open a file, search the web or send an email. Yet coding agents fix bugs, and assistants book meetings. The model is the same; the software around it lets the model ask for things, does them on its behalf, and shows it the result.

A model that asks for things

The model still only writes text. A tool call is text in an agreed format: which tool, and with which inputs. Generation stops there. Ordinary software, the harness, reads the request, runs the tool, pastes the result into the conversation and asks the model again, with everything so far. That repeats until the model answers without asking for a tool.

The field now describes agents in exactly these terms. Simon Willison's one-line definition has become the common one: an LLM agent runs tools in a loop to achieve a goalsource. It also separates agents from simpler setups. Anthropic's engineers draw the line like this: in a workflow, code decides the order of steps; agents are systems where the model directs its own process and tool usesource. A support bot that always looks up an order and then drafts a reply is a workflow. One that decides for itself whether to look something up, ask a question or escalate is an agent.

Step through a session

Here is a coding agent fixing a failing test. Step through it, then use the switches. “Show raw messages” shows what actually goes back and forth: the tool call is a small block of structured text, and the result comes back as one more message. “Plant an instruction in a file” shows what happens when a file contains a sentence written for the AI.

Context

A typical, simplified coding-agent session. Token counts are realistic orders of magnitude. The raw view uses one provider's message format, shortened; other providers use different names for the same shape. Cost assumes cached input is billed at a tenth of the normal price.

All continuity lives in the transcript. There’s no agent thinking in the background between steps: the same unchanged model reads a longer text each time. And the model never does anything itself. Every action passes through the harness, which is why the harness is where permissions, limits and logs belong.

Small mistakes add up

An agent task is a chain of steps, and any step can go wrong: a misread error message, a wrong file, an edit in the wrong place. If each step goes right nearly every time, a long chain still breaks surprisingly often. Try it:

How small mistakes add up

chance that every step goes right

A toy model: every step fails independently with the same chance, and the check catches every failed step and allows one retry. Real agents break both assumptions, as the text below explains.

At 99% per step, a fifty-step task runs cleanly only about six times in ten. That simple multiplication is a useful intuition. Real agents depart from it in two ways that matter:

  • Mistakes aren’t coin flips. Some tasks an agent gets right nearly every time, others it fails nearly every time. That makes repeated runs more consistent than the multiplication predicts, as the measurements below show.
  • Checks change the maths. When the loop includes something outside the model that can say “wrong”, such as a test, a compiler or a real tool result, the agent can notice a failed step and try again. Add the check in the demo and the chance of a clean run jumps.

Where experts disagree checked Nov 2026

Do small errors doom long agent tasks, or can good design beat the arithmetic?

If every step can fail, long tasks look hopeless on paper, yet agents finish multi-hour jobs.

Errors compound, so long tasks stay fragile

Toby Ord; METR; the MAKER authors on today's models

  • Success on long tasks fits a constant chance of failing each minute, so success falls off exponentially with task length.
  • Agents handle single skills well but struggle to string long sequences of actions together.
  • Models keep a persistent error rate that, left alone, derails a long process.

Sources: arxiv.org · metr.org · arxiv.org

Design can beat the arithmetic

Sinha and colleagues; Meyerson and colleagues (MAKER); Anthropic's agent guidance

  • Small gains in per-step accuracy compound into much longer tasks, and thinking reduces the knock-on effect of earlier mistakes.
  • Splitting work into tiny steps with voting completed over a million steps without error.
  • Checks against the real world at every step (tests, tool results) let an agent catch and fix its own mistakes.

Sources: arxiv.org · arxiv.org · anthropic.com

What would settle it: Long-task measurements that report how often agents succeed every time, not just once, with and without verification steps.

How reliable is it today?

Getting a single tool call into the right format is the easy part, especially with modes that force valid arguments. Long, realistic tasks are another matter.

Researchers measure two things: solved on at least one of several tries, or solved on every try. The τ-bench authors introduced pass^k, which asks whether an agent succeeds on every one of k tries; in 2024 the best agent passed all eight tries on under a quarter of retail tasksNov 2026. A demo needs one success. A business that hands the same kind of task to an agent every day needs the second kind, pass^k, and that number is much lower.

When does it stop?

A loop needs a way out. Usually the model ends its turn without asking for a tool, and the harness treats that as “done”. The harness also sets hard limits on steps, cost and time, because a model can stop too early or not at all. When agents fail is about catching the model that declares victory too soon.

Every step costs

Each step sends the whole transcript to the model again: the instructions, the tool descriptions, every earlier call and result. So the amount of text the model reads grows faster than the number of steps. Agents read far more than they write, and they cost more than chats. Anthropic reports that its agents typically use about four times the tokens of a chat, and its multi-agent systems about fifteen times (self-reported)Nov 2026.

What keeps this affordable is prompt caching: the provider charges far less for the beginning of a prompt it has already processed. Switch caching off in the demo to see the difference. This is also why well-built harnesses avoid changing anything near the start of the context.

Engineer depthInside a tool call, and how to measure an agent

Under the hood, every major provider uses the same shape. You can rely on that across vendors; the field names differ.

Tools are declared as schemas. Each tool has a name, a description and a JSON Schema for its inputs. The model writes a structured call and the API reports why generation stopped (a tool request or the end of the turn). Strict or structured modes constrain decoding so the arguments always match the schema. A tool-choice setting lets you let the model decide, force a tool call, forbid one or require a specific tool. Models can also request several tool calls in one step, which the harness may run in parallel. Some tools run on the provider’s side, such as hosted web search or code execution, so “your code runs the tool” isn’t always literally true.

Tool definitions are prompt text. Names and descriptions are read by the model on every call and billed as input. Treat them like prompts: precise, with examples of when not to use the tool. A vague description is a common cause of wrong tool choices, and a malicious one is an attack, as Part 3 shows.

Workflow or agent is a design choice, not a ranking. If the steps are known, write them as code and let the model fill in each one. It’s cheaper, easier to test and easier to secure. Reach for an agent loop when the path genuinely depends on what the model finds. Whether to split work across several agents is contested; it pays off mainly when subtasks are independent, and it multiplies token use.

Measure reliability, not luck. pass@k (at least one of k tries) rises with k and flatters a system. pass^k (all k tries) falls with k and matches what a deployment experiences. Comparing the two also shows how correlated failures are: if tries were independent, pass^4 would be pass@1 to the fourth power, far below what benchmarks such as MCPMark actually measure. On MCPMark, a 2025 benchmark of realistic multi-step tool tasks, the best model at publication solved 52.56% of tasks on one try, but only 33.86% on all four of four triesNov 2026.

Treat leaderboards with care. Epoch AI rated the most-cited function-calling leaderboard, BFCL, 'Flawed' in September 2026, after finding defects that could affect accuracy in 48% of a sample of its tasksNov 2026. Benchmarks also change version, and scores across versions aren’t comparable. Report cost and number of steps alongside accuracy, and test on your own tasks with your own harness, because results depend on the scaffold as well as the model.

Engineer the stop. Combine the model’s own end of turn with hard caps on steps, tokens, wall-clock time and spend, and a stop when the same failing action repeats. Log every call and result. The transcript is your audit trail, your debugging tool and your evaluation data. Where the pattern comes from. The ReAct paper (Yao and colleagues, 2022) had a model alternate between writing down its reasoning and taking an action, a pattern today's agents still resemblesource. Toolformer (Meta, 2023) showed that a model could teach itself when to call tools such as a calculator, a search engine or a calendarsource. Today’s models learn tool formats as part of their training and use them far more reliably than those first experiments.

How far the multiplication holds. A constant chance of failure per step is roughly what some researchers see in the data. Toby Ord found that agents' success on longer tasks fits a constant chance of failing in every minute of work, so each agent can be described by a 'half-life'Nov 2026. Two results pull in opposite directions. Mistakes breed mistakes: models become more likely to make mistakes when their own earlier mistakes are in the context, and letting them think before answering reduces the effectNov 2026, so a bad early step can make later ones worse. And design can push reliability a long way: a research system that split a task into tiny steps and let several model calls vote on each one completed over a million steps without a single errorNov 2026. That was an extreme lab set-up, and it shows how much of the limit lies in the system around the model.

Caching has a condition. Anthropic bills cached input at a tenth of the normal price, less on its newest models, but only when the beginning of the prompt is exactly identicalNov 2026.

Recall. In an agent, who actually carries out a tool call such as 'delete this file'?

Apply it. An agent completes a demo task on the first try. Before you give it the same kind of task every day, what should you find out?

Spot the mistake. A colleague says: 'Between steps the agent is thinking in the background, so I shouldn't interrupt it.' What is wrong?

Remember this

  • An agent is a model called again and again. Its tools run in ordinary software, the harness, in between.
  • Small error rates multiply over many steps. Checks outside the model bring reliability back.
  • Whatever a tool returns enters the conversation as text. That is the door prompt injection uses.

Further reading

Spotted a mistake? Report it on GitHub. Every fix is listed in the monthly field notes.

Contents

In this chapter

From chat to agent: tools and the loop

    Part 1: Language models

    1. 1Start here6 min
    2. 2Tokens10 min
    3. 3Attention10 min
    4. 4The stack9 min
    5. 5Generating12 min
    6. 6Training11 min
    7. 7Beyond autocomplete15 min
    8. 8Strengths & limits12 min

    Part 2: Agents

    1. 1The agent loop12 min
    2. 2Context and memory13 min
    3. 3Around the model12 min
    4. 4Agents at work13 min
    5. 5Agent failures13 min

    Part 3: Trust & security

    1. 1Prompt injection14 min
    2. 2Agents and permissions13 min
    3. 3Supply chain12 min
    4. 4Your data12 min
    5. 5Patch gap12 min
    6. 6Judging claims15 min

    Part 4: Looking ahead

    1. 1Frontier11 min
    2. 2On one page4 min

    Guide

    Settings

    Engineer boxes
    Text size
    Theme