Agents · The basics

The agent loop

Idea

Under the hood, most agents are a model running in a loop. Each turn, the model reads the goal and everything so far, decides on one action (search, run a command, open a file), and the result is fed back in for the next turn.

The loop ends when the model says it is finished, when it hits a limit you set, or when it stops to ask you something. Most of the craft of building agents is deciding what goes into each turn and when the loop should stop.

For example

Fixing a failing test: run the tests, read the error, edit the code, run the tests again. Four turns of the same loop.

More in The basics