Agent Loop

The cycle of observing a result, choosing the next action, and repeating until a task completes or stops.
Updated 6 Oct 2026

In an agent loop, the model is not following a closed sequence of predefined steps. It observes the available state, chooses an action, receives the result, and decides again with that new information.

Agent loop The agent observes, decides, acts, and receives a result. That result becomes the next observation until the goal is reached and the agent finishes. Task Observe Read the latest inputor tool result Decide Choose the next stepfrom that result Act Call a tool orreturn an answer Result Receive output fromthe environment Next observation Finish Agent loop The agent observes, decides, acts, and receives a result. That result becomes the next observation until the goal is reached and the agent finishes. Task Observe Read the latest inputor tool result Decide Choose the next stepfrom that result Act Call a tool orreturn an answer Result Receive output fromthe environment Finish Next observation
Figure 1. The agent uses each action result to choose the next step or finish.

Coding-agent example

An agent is asked to fix a failing test:

  1. It runs the test and observes the error.
  2. It reads the test and related code.
  3. It edits a file.
  4. It runs the test again.
  5. If it still fails, the new error determines what to inspect next.
  6. If it passes and the task is complete, the agent stops.

The number of reads, edits, or test runs was not fixed at the start. Each result changes the information available for the next step.

Tools and execution

The model normally expresses an action as a tool call. The harness performs the operation — for example reading a file, changing code, or running a test — and returns the result as a new observation.

A sequence that uses tools is not necessarily agentic. In a fixed workflow, the operations are defined in advance. In an agent loop, the result of one operation can change which action is chosen next.

Stopping

The stopping condition needs to match the complete task. If the request requires fixing a test and running the build, a passing test still leaves one validation step outstanding.

The loop can also stop because it needs a user decision, an action requires approval, or no useful progress is possible with the available information. Repeating the same command after the same failure adds no evidence; the next step should change the hypothesis, ask for help, or stop.

References