The Agent Loop and Acting
The agent loop and ReAct
Perceive, reason, act, observe
One LLM call answers a question. A loop around that call, reason, act, observe, repeat, is what turns the model from a text generator into an agent. This lesson is the spine of the whole course: the agent loop, and its most famous shape, ReAct.
The loop is the whole idea
An agent is not a smarter prompt. It is an ordinary LLM placed inside a control cycle that runs until a goal is met. The most widely agreed definition is deliberately mechanical: an LLM agent runs tools in a loop to achieve a goal.[1] The load-bearing words are in a loop, the line between a one-shot tool call and a real agent. Anthropic phrases it the same way: agents are "typically just LLMs using tools based on environmental feedback in a loop."[2]
The loop has four beats. The model perceives the current state, reasons about what to do, acts by calling a tool, then observes the result, and that observation becomes the next perception. It repeats until the goal is satisfied or a stopping condition fires.
Tap a node to see what it does.
Cross-reference the definitions you already met: a single LLM call is not an agent, and this loop is exactly the component the anatomy lesson called orchestration. This is where all of it becomes concrete.
Why the loop is what makes it an agent
Ask a bare LLM "what other device controls Front Row?" and it must answer from parametric memory: it might be right, it might confidently invent an answer. Give it a search tool once and you have tool use, not an agent: it runs the tool a single time and stops, never using what came back. The loop changes the physics. After every action the model receives ground truth from the environment, a tool result, a code-execution output, an error, and reasons again from that fact.[2] That feedback is what lets the system self-correct against reality instead of drifting.
The discriminator
ReAct: reasoning and acting, interleaved
is the canonical shape of the loop. Instead of separating "think" from "do," it interleaves them into a repeating three-part cycle, Thought, Action, Observation, until an action like Finish[answer] ends it.[3] The payoff is a two-way synergy:
Reason then Act
Act then Reason
A real ReAct trace
Here is the canonical worked trace from the ReAct paper, a two-hop question answered by interleaving thoughts with Search calls against a Wikipedia API.[3][4] Watch how a failed search in Obs 2 is recovered by the reasoning in Thought 3, the moment an act-only agent would stall.
Q: Aside from the Apple Remote, what other device can control the
program the Apple Remote was originally designed to interact with?
Thought 1 Search Apple Remote, find the program it was designed for.
Action 1 Search[Apple Remote]
Obs 1 ... introduced in 2005, originally designed to control the
Front Row media center program ...
Thought 2 It controls Front Row. Search Front Row next.
Action 2 Search[Front Row]
Obs 2 Could not find [Front Row]. Similar: ['Front Row (software)', ...]
^ failed search
Thought 3 Front Row is not found. Search "Front Row (software)".
^ the recovery: reasoning reformulates the query
Action 3 Search[Front Row (software)]
Obs 3 ... controlled by an Apple Remote or the keyboard function keys.
Thought 4 So the answer is keyboard function keys.
Action 4 Finish[keyboard function keys]Read the recovery
Search commands would be stuck at Obs 2. A pure reasoning agent (chain-of-thought, no tools) would never have discovered "Front Row" at all and might guess "iPhone" from memory. Interleaving both lets the agent reformulate the query, do the second hop, and ground the final answer in real text.Four ways to answer the same question
The ReAct paper ablates the design by stripping components. Only the version with both reasoning and acting survives a failed search:[4]
| Style | Reasons? | Acts (tools)? | Failure mode |
|---|---|---|---|
| Standard | no | no | Answers blind, often wrong, no trace to inspect. |
| Chain-of-thought | yes | no | Hallucinates the intermediate facts, never checks them. |
| Act-only | no | yes | Cannot recover from a failed action or plan a second hop. |
| ReAct | yes | yes | Recovers, grounds each step, answers correctly. |
ReAct is not always the winner: on pure closed-book recall it can lag chain-of-thought with voting, and the strongest setup often switches between the two. But for any task where the agent must gather external info or act in an environment, ReAct is the default.[4] Modern tool-calling agents, including Claude's tool use, are ReAct at production scale.[2]
The loop is a generate then verify cycle
Zoom out and the loop has a rhythm: the model generates a candidate action, the environment verifies it by returning a real result, and the next generation is conditioned on that verification. Karpathy frames the whole discipline of building agents as keeping this generate then verify loop tight and fast, with a human able to watch it.[5] It is why the agent-friendly domains are the verifiable ones: a coding agent generates a patch and the test suite verifies it, and the failing test becomes the next observation. When there is no cheap verifier, the loop has nothing to self-correct against, a theme the reflection lesson pushes further.
Stopping conditions and step limits
A loop with no exit is a bug, not an agent. Every observation costs tokens and latency, and an early mistake can propagate through the whole chain, so the loop needs an explicit bound.[6] Real agents stop on one of four conditions:
- Goal satisfied. The model emits a terminal action (
Finish[...]) or otherwise signals the task is done. - Step or iteration budget. A hard cap,
max_iterations, so a confused agent cannot spin forever burning tokens.[2] - Blocker or human checkpoint. It pauses for a human before an irreversible write (a payment, a delete) or when it hits something it cannot resolve.
- Loop detection. The same action producing the same observation repeatedly means the agent is stuck, a classic "make progress or stop" heuristic.[7][8]
Unbounded loops are the default failure
Check yourself
Match each beat of the agent loop to what happens there.
read the current context
plan the next action
call a tool
the tool result becomes the next perception
In a ReAct loop, what does the Observation step provide that pure chain-of-thought reasoning lacks?
Name the three repeating steps of a ReAct cycle, in order, and what ends the loop.
What ends it? Try to state it, then check.
Lock it in
- The loop makes the agent: perceive, reason, act, observe, repeat. A one-shot tool call is tool use; iterating on the result is an agent.
- Observations inject ground truth. Real tool results re-anchor the model each step, the antidote to chain-of-thought's unchecked hallucination.
- ReAct is Thought, Action, Observation interleaved. Reasoning steers actions and handles exceptions; actions feed reality back into reasoning.
- It is a generate then verify cycle. Agents work best where progress is cheaply verifiable: code, search, environments.
- Always bound the loop. Stop on goal met, a step limit, a human checkpoint, or loop detection, never leave it open-ended.
Primary source
Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models (ICLR 2023)The origin of the Thought, Action, Observation loop, the worked Apple-Remote trace, and the ablation that shows why interleaving beats reasoning-only and acting-only.
Sources
- 1.Simon Willison, Tools in a loop (2025)
- 2.Anthropic, Building Effective Agents
- 3.Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models (ICLR 2023)
- 4.Prompt Engineering Guide, ReAct Prompting
- 5.Andrej Karpathy, 2025 LLM year in review
- 6.Chip Huyen, Agents (2025)
- 7.Shinn et al., Reflexion (2023)
- 8.Lilian Weng, LLM Powered Autonomous Agents (2023)