Skip to content
The Daily Triptych091 / 365
The agent loop

Each iteration: the model sees the current state, reasons about what to do next, the system executes the action, and the result becomes the next observation. Errors compound, but so do corrections.

II · THE IDEA · ARTIFICIAL INTELLIGENCE

Agents

Systems and judgement · Observe–decide–act loop with language model at the core · ReAct (Yao et al., 2022)

▶ Listen · narrated

One bad step in a chain of reasoning costs you the answer. One bad step in a loop costs you only that iteration, provided the agent notices.

At a glance

What it is
A system that repeatedly calls a language model to observe state, reason about it, then take an action
Core structure
Loop: read environment, generate reasoning and action, execute action, observe result, repeat
Error behaviour
Errors compound across iterations; short loops with feedback limit damage
ReAct contribution
Interleaving explicit reasoning traces with actions, rather than planning then acting

Imagine you are assembling furniture with instructions that only reveal one step at a time. You read step one, do it, then the instructions show you step two based on what you actually built — not what the manual assumed you would build. If you put a bolt in the wrong hole, step two might say "remove the bolt from the left hole and use the right one" because it can see what you did. An agent works the same way: it asks the language model for the next action, does that action, shows the model what happened, and asks again. The model never sees the whole plan upfront. It decides each step after learning whether the previous step worked, which means a mistake in step three does not ruin steps four through ten — because those steps have not been decided yet. The model gets to adjust. The trade-off is that you are asking the model to make more decisions, and each one is a chance to go wrong, so agent systems usually add limits: a maximum number of steps, checks that the model is not hallucinating success, and sometimes a human watching to press stop if things drift too far off course.

Look closer

  1. The model generates both the reasoning and the action

    In the ReAct formulation, the model outputs a thought — an explicit reasoning step written in natural language — then an action, such as calling a search tool or manipulating a file. That thought is not just for human inspection; it becomes part of the prompt on the next iteration, so the model sees its own reasoning history. This differs from earlier approaches that separated a planning phase from an execution phase. Here, thinking and acting interleave, and the model can revise its plan as new observations arrive.

  2. Short loops beat long plans in practice

    A model asked to generate a ten-step plan upfront will produce something plausible, but each step depends on assumptions about what earlier steps will yield. If step three fails or returns unexpected data, steps four through ten may become nonsensical. A loop that decides only the next action, observes the result, then decides again confines each error to one iteration. The cost is more model calls, but the benefit is that the agent can adapt. This is why agent systems tend to favour narrow action spaces and frequent check-ins over elaborate advance planning.

  3. The loop is not the model; the loop is code around the model

    The language model itself has no memory between calls and no ability to execute actions. The agent system — written in Python, JavaScript, or another host language — maintains the loop, appends observations to the prompt, parses the model's output to extract actions, calls external tools, and decides when to stop. If that orchestration code has a bug, or if it fails to validate tool outputs, the model cannot fix it. The model only sees text; the agent system is what makes that text consequential.

The story

An agent is a language model wrapped in a loop. The model does not act on the world directly; it generates text that describes an action, and code outside the model executes it. Then the loop runs again, feeding the result back as a new observation.

The canonical structure, formalised in the ReAct paper by Yao and colleagues, looks like this: the model receives a prompt containing the task, the history so far, and the most recent observation. It generates a reasoning step — a sentence or two explaining what it thinks should happen next — then an action, such as "search for population of France" or "read file data.csv". The agent system parses that action, calls the appropriate tool, captures the result, appends it to the history, and calls the model again. The model now sees its own previous reasoning, the action it chose, and the outcome. It decides what to do next.

This differs from asking a model to generate a complete plan upfront. A plan written in advance assumes each step will succeed and return the expected information. When reality diverges — a file is missing, a search returns nothing useful, an API times out — the rest of the plan becomes wishful thinking. The agent loop adapts because it observes after every action. If the model searches for "France population 2023" and gets back a disambiguation page, it can refine the query on the next iteration. If it tries to open a file that does not exist, it can list the directory instead.

The price is compounding error. Each iteration depends on the model correctly interpreting the previous observation, generating sensible reasoning, and formatting a valid action. If any of those steps fails, the next iteration starts from a flawed state. The model might misread a number, call a tool with malformed arguments, or hallucinate that an action succeeded when the observation says it failed. The loop continues, and the errors accumulate. This is why short loops with tight feedback are safer than long autonomous runs: fewer iterations mean fewer opportunities for drift.

The ReAct paper demonstrated that interleaving reasoning and acting outperformed both pure reasoning (chain-of-thought prompting with no actions) and pure acting (choosing actions without explicit reasoning steps) on question-answering and decision-making benchmarks. The reasoning traces helped the model stay coherent across multiple steps, and the ability to act let it retrieve information it could not generate from memory alone. But the improvement was modest, and the error rate rose with the number of iterations.

Agent systems in practice often add guardrails: hard limits on loop iterations, validation of tool outputs before they re-enter the prompt, and human-in-the-loop checkpoints for high-stakes actions. The loop is powerful because it lets a model recover from mistakes, but it is also fragile because every cycle is a chance to fail in a new way.

Why it mattered then

The ReAct paper, published in 2022, arrived at a moment when large language models had demonstrated strong reasoning ability in static prompts — chain-of-thought techniques were showing that models could solve multi-step problems if you asked them to show their work — but there was no established method for letting them interact with tools or data sources during that reasoning. Earlier agent architectures, often built on reinforcement learning, required task-specific training and did not generalise well. ReAct showed that a pre-trained language model, given nothing but a prompt format that alternated reasoning and acting, could learn to use tools effectively from a handful of examples. This mattered because it suggested that the same models being used for text generation could, with the right scaffolding, perform tasks that required looking things up, running code, or manipulating files. It moved the bottleneck from model capability to system design: the question was no longer whether a model could act, but how to structure the loop so that it acted reliably.

Why it matters now

Agent systems are now a standard deployment pattern for language models in production. They power coding assistants that read documentation and run tests, customer service bots that query databases and update records, and research tools that search papers and synthesise findings. The loop structure has become infrastructure: frameworks like LangChain and AutoGPT codify it, and cloud providers offer agent orchestration as a service. But the core fragility remains. Every agent system in production has to solve the same problems: how many iterations to allow before giving up, how to validate tool outputs so hallucinated success does not propagate, and how to surface the reasoning trace so a human can audit what went wrong. The agent is still not autonomous in the sense of being trustworthy without oversight. It is autonomous in the narrower sense that it can try things, observe the results, and try again — which turns out to be useful enough, and risky enough, that the design of the loop now matters as much as the capability of the model inside it.

The surprising detail

The reasoning traces that agents generate — the "thought" step in ReAct — are not reliably faithful to the model's actual decision process. The model generates the reasoning as text, in the same forward pass that generates the action, and there is no guarantee that the reasoning caused the action rather than being a plausible post-hoc rationalisation. In some experiments, researchers have found that removing or scrambling the reasoning trace in the prompt history has little effect on subsequent actions, suggesting the model is not always reading its own reasoning as carefully as the system designers assumed. This matters because agent systems often log and display these traces as explanations, and users may trust them more than they should. The thought is part of the output, not a window into the mechanism.

Remember this

An agent is a loop, not a model. The loop decides when to stop, what to retry, and which errors to tolerate. Design the loop badly and the model cannot save you.

Test yourself

An agent runs for twelve iterations and solves the task. On iteration seven, it called a search tool with a slightly malformed query, and the tool returned an error message. Why might the agent have succeeded anyway?

Go deeper

Image: Original diagram, The Daily Triptych. Licence: Original work. Source.

← Back to day 91