AssayAssay
03 / 08

Lesson 03 · Control · 12 min

How loops end

A loop ends when your code stops calling the model. The model itself only signals: a reply containing no tool call is the conventional way of saying "I am finished". Treating that signal as the only exit is what produces agents that run until the money does.

Three exits are worth implementing from the beginning, and they mean different things:

AnsweredThe model returned a final reply with no tool call. The only exit that indicates success — and even then, only that the model believes it is done.
Budget exhaustedThe iteration ceiling was reached first. Not necessarily a failure, but the answer is incomplete by definition.
No progressThe loop was still running but no longer getting anywhere. Covered in lesson 5.

Report which exit was taken. A system that returns an answer without saying how it stopped hides the difference between a finished agent and one that was cut off mid-thought — and those need very different handling downstream.

The lab shows the exit as a coloured label after each run. Try the refund task with the budget set to two and watch it end unfinished, then raise it and watch the same task complete.

Checkpoint

Find the smallest budget at which the refund task completes on your chosen model.

“Where is my order 41902? It hasn't arrived yet.”

The shortest useful loop: one tool, one answer. A model that replies without calling anything is inventing the status.

Run the refund task with a low budget so it ends unfinished, then raise the budget until it answers. Note how many iterations it genuinely needed.

Nothing has run yet. Pick a task and press Run — every iteration appears below.