Knowledge tree
On this page

Agent Loop

The cycle in which an agent observes a result, chooses the next step, acts, and repeats until it can stop.
Updated 28 Aug 2026

An agent loop repeats a simple sequence: observe the current state, choose the next step, act, receive the result, and decide again.

What makes it useful is that the result changes what happens next. The complete path is not fixed in advance.

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 agent did not need to know in advance how many files it would inspect or how many test runs would be required. Each result informed the next action.

Tools and execution

The model does not normally change the environment itself. It proposes a tool call and the harness performs the operation: read a file, edit code, or run the test. The result returns to the model as a new observation.

One tool call does not automatically make an application an agent. It may be one step in a fixed sequence. A loop exists when the system decides again from the result and can change direction.

Stopping

The loop needs a useful completion condition. In the example, a passing test is not enough if the task also requires a successful build. The success condition includes all requested validation.

The loop can also stop because it needs a user decision, an action requires approval, or no safe progress is possible. Repeating the same failing command without changing anything is not progress. The result should lead to a different hypothesis, a request for help, or a stop.

Fixed workflow versus agent loop

In a fixed workflow, the stages are already known: parse a file, validate its schema, then store it. In an agent loop, the model chooses among available actions according to what it finds.

Both can work together. The agent chooses to run the tests, while the test runner remains deterministic software with predefined behavior.

Tool Use covers how a tool call executes. Agent Harness covers the program that maintains this loop.

References