The loop: observe, decide, act

One move, repeated: look at what happened, choose the next action, do it, look again.

Part of the Agents track on lAItest.

Watch an agent work and you see one move on repeat: look at what came back, pick the next action, do it.

Everything else is bookkeeping.

One step of the loop

The program sends the model everything so far: the goal, the tools available, and the record of every action taken and every result returned. The model replies with either a final answer or a request to use a tool. If it is a request, the program runs it, appends the result to the record, and sends the whole record again. Nothing carries between steps except that record. The model does not remember; the transcript remembers for it.

Knowing when to stop is the hard part

A loop needs an exit. In practice there are three: the model says it is finished, a step or budget limit is hit, or a human intervenes. Agents rarely fail by picking a wildly wrong tool. They fail by not noticing they are stuck, and repeating a failing action until something outside them runs out.

Try it

Every step resends the whole transcript. Raise the number of steps and watch what happens to input tokens. This step is an interactive widget; open the lesson to use it.

What a step costs on Claude Opus 5

Read from a live model index at page-render time, each figure linked to the vendor page it came from.
WhatValueProvenance
Input, per million tokens$5 per 1Msource, verified . Paid again on every step, because the transcript is resent
Output, per million tokens$25 per 1Msource, verified . Hidden reasoning tokens bill at this rate too

In one sentence

An agent is a while-loop with a language model as its decision function, and the exit condition is the part that bites.