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:
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.