Back to list

Tech Blog · AI Agents

[AI Agent Basics 5] The agent loop: observe → plan → act → check

Unlike a chatbot that answers once and is done, an agent repeats observe, plan, act and check until it reaches the goal. We look at when this loop stops and where it goes wrong.

Jun 30, 2026 · OPTI-X

Basics series “How AI Agents Are Built” · Part 5

In the last part, we saw that a model can request tool calls. Now, what happens if we let it exchange those requests and results many times? The model looks at the result and decides its next action, then looks at that result and decides the next action again. This is an agent.

Consider the request "Find out why the neutralization tank pH fluctuated last night." The agent has to look at the chemical dosing history, then the inflow rate, and decide which data to look at next based on what it has found. A single lookup will not finish the job.

The four steps of the loop

The agent loop

Repeats until the goal is reached or a stop condition is met

  1. 1
    ObserveReads the goal, the results so far and the information returned by tools
    Next
  2. 2
    PlanThinks about what to do next (reasoning)
    Next
  3. 3
    ActCalls a tool (lookup, calculation, file edit, etc.)
    Result received
  4. 4
    CheckJudges whether the goal has been reached or the iteration limit has been hit
    Not yet → back to ObserveLimit reached → stop and report to a personDone → report results

The key to the loop is that the result of each step becomes the input to the next. As the ReAct paper describes it, at every step the agent reads the goal and the full record of its actions and observations so far, then chooses its next action. The result of that action (the observation) is appended to the end of the record.

In this structure, "thinking" is also a kind of action. A thought, however, does not change the outside environment; it is only added to the record. The paper lists what thoughts are used for: breaking the goal into smaller steps, extracting the important parts of an observation, tracking progress, and revising the plan when an exception occurs.

Why alternate thinking and acting

The ReAct study, published in 2022, showed that alternating thinking (reasoning) and acting (tool use) performs better than doing only one of the two. On ALFWorld, where an agent carries out multi-step tasks in a text-based simulated household, the alternating approach reached a 71% success rate versus 45% for acting only (best trial of each). Acting alone often failed to break the goal into smaller steps or lost track of the current state.

Conversely, thinking without looking anything up leads to made-up facts. On Wikipedia-based question answering (HotpotQA), 56% of the failures of the thinking-only approach came from made-up facts, versus 0% for ReAct. Most agents today are built on this structure.

Chatbots vs. agents

The difference is repetition and tools

Chatbot
Agent
Per request
Answers once
Repeats thinking and acting many times
Tools
None, or once
As many times as needed
Output
A written answer
Completed work (files, analysis, edits)
How it fails
A wrong answer
Wrong actions pile up

When does the loop stop

An agent can declare "done" on its own, but relying on that alone means it may loop forever or stop too early. So stop conditions are placed outside the loop. The ReAct study set the maximum number of steps for question answering at 7 (HotpotQA) and 5 (FEVER). Among trajectories with correct answers, only 0.84% went as far as 7 steps, so adding more steps did not improve performance; when no answer came within the limit, the task was handed to another method.

The number of iterations is also the cost. Because the agent rereads its entire record at every step, the amount it reads each time grows as the steps add up. The follow-up study Reflexion stopped an attempt when the agent received the same result for the same action more than 3 times, or when it took more than 30 actions in one task. The cause of failure was written up and passed to the next attempt, and through repeated attempts the agent completed 130 of 134 ALFWorld tasks.

Problems that grow as the loop gets longer

The loop is powerful, but the longer it runs, the greater the risk. If a small misunderstanding arises at one step, the next actions are stacked on top of it. The agent may get stuck repeating the same action, or declare "done" before the goal is fully reached. The ReAct authors' own classification of failure cases shows this problem as well.

Types of ReAct failures

50 HotpotQA failure cases classified by people · repetitive loops and uninformative search make up 70%

Reasoning error (incl. repetitive loops)
47%
Ambiguous answer label
29%
Search result error
23%
Made-up facts
0%
Source: Yao et al., ReAct (ICLR 2023), Table 2, redrawn

Reasoning errors include cases where the agent keeps repeating its previous thoughts and actions and cannot get out of the loop. When search results were empty or uninformative, the reasoning that followed was derailed and hard to recover.

Wrong observations pile up as they are. A common failure in the Reflexion study was an agent believing it was holding an item when it actually was not. The agent kept acting on that belief and could not trace back to find the mistake. On a plant, this is like looking up the pH tag of a different tank and continuing the root-cause analysis based on that value.

What to check before connecting it to a process

An agent survey divides the feedback that enters the loop into three kinds: the environment (execution results and observations), people, and the model itself. Of these, leaving the check to the model's own judgment is not enough. Research shows that when a language model is asked to review its own answers without external feedback, performance on reasoning tasks does not improve and sometimes even drops. Checks should rely on signals from outside the model, such as measurements, calculations and rule checks.

On a plant, actions also differ in weight. A history lookup has no effect on equipment no matter how many times it runs, but changing a chemical dosing rate or a rolling mill roll gap is hard to reverse. Because results take time to appear after a setpoint changes, the check step should wait for the process to respond before judging.

What makes a good agent loop

Loop design often matters more to the outcome than the model

Stop conditionsBe clear about when to finish
Set a maximum number of iterations, repeated-action detection and completion criteria in advance
Observation checkVerify the data it read first
Check lookup results first: equipment, time range and units match the request
Check stepVerify the results of actions
Build signals from outside the model, such as measurements, recalculation and rules, into the loop
Human involvementAsk at important forks
Approval before hard-to-reverse actions

Because thoughts are left in writing, a person can also read the intermediate record and correct it. The ReAct paper includes a case in which a person turned a failing task into a success by editing two of the agent's thoughts.

Whether an agent can be trusted depends as much on the loop's stop conditions and checks as on the model. In the next part, we look at what an agent remembers, and what it forgets, as the loop gets longer.

References

Could this work for your process?

Talk to us