Learn / Explainers / The agent loop: four beats and three exits

The agent loop: four beats and three exits

Animated explainer · 2:51 · from Chapter 3

Space plays and pauses · ← → step · F fullscreen

A three-minute animated explainer of the agent loop: the four beats of every pass, the history that is the agent's only memory, and three exits ranked by trust.

Transcript

Every step of the animation, in the words it uses on screen. Select a line to jump to it.

From Chapter 3

The Agent Loop

This explainer condenses a few pages of Chapter 3, which is in the full book. The chapter traces the ideas through a worked example; the preface and Part I are free to read online.

Questions

What are the four beats of the agent loop?
Observe (lay everything the model needs on the desk: instructions, goal, history, latest result), reason (one call to the model, which decides the next move), act (the decision arrives as a tool call or a final answer), and observe the result (your code runs the tool and appends what came back to the history). Then the desk is laid again and the cycle repeats.
Why does an agent need a step budget if the model can say when it is done?
Because the model's "done" is testimony, not evidence: it can declare victory early or never declare it at all. A budget on passes, tokens, time, or money is enforced by the harness and indifferent to the model's opinion, so it guarantees the loop stops. It should be the first thing you write.
Where does an agent's memory live?
In the history your code appends to. The model remembers nothing between passes; whatever the loop appends is the agent's memory, and whatever it fails to append never happened. The two append lines in the pseudocode are load-bearing.