Notes

Agent Loop

A single model call answers a question. An agent finishes a task, and it does that by going round in circles on purpose. The agent loop is that cycle: look at the current state, decide one next step, carry it out, read the result, and go round again until the goal is met or a limit stops it.

The three moves
Every iteration is the same shape:

  • Observe — the model receives the goal, the history so far, and the output of the last tool call.
  • Decide — it reasons about what remains and emits either a tool call or a final answer.
  • Act — the runtime executes the call and appends the result as the next observation.

None of this is new model capability; the loop is ordinary control flow wrapped around an ordinary completion call. That is the whole trick, and it is why ReAct — interleaving reasoning traces with actions — was a small change with large consequences.

Where loops fail
The loop also manufactures every characteristic agent failure. It repeats a failing call until the step budget is gone. It drifts because an early instruction fell out of the context window. It declares success without verifying. Real implementations therefore bound it: a maximum step count, a spend cap, a termination condition the model does not control, and a trace per iteration so drift is visible afterwards. LangGraph makes the loop an explicit graph for exactly this reason.

Why it matters
The loop is what separates an agent from an assistant: it lets a system notice and recover from its own mistakes mid-task, which no single call can do.

The agent loop is the repeating cycle through which an agent makes progress: observe the current state, decide the next step, act, then feed the result back as a new observation. Iteration continues until a termination condition is met. The loop is what separates an agent from a single model call — it lets the system correct course on real feedback instead of committing to one upfront answer.

Ask a satnav for directions and you get one answer. A driver finding an unfamiliar address works differently: look around, make one turn, see what happens, look again. The agent loop is software working the second way.

Instead of producing a single reply and stopping, the program takes one small step towards the goal, checks the result, then decides what to do next. Round and round, until the job is done.

That is what lets it cope when something unexpected turns up — a page that will not load, a file that is missing. It is also why these systems need a firm stop rule, or they will keep circling on a step that is never going to work.