When should an agent loop stop?

L1 · FundamentalsConcept~6 minThe agent loop

"List every reason an agent loop should stop, and for each one, what the user should see."

Answer it out loud or on paper first. Then open the short answer.

Short answer

The happy stop is the model answering without a tool call. Everything else is a guard: step limit, token or cost budget, wall-clock timeout, detected loop or no progress, an unrecoverable error, a tool that needs human approval (pause, not stop), a user interrupt, and a policy violation. Each stop should carry a reason, and the user should get something useful for each: the answer, a partial result with what's missing, a request for approval, or a clear explanation of what failed.

Full answer
Stop reasonTriggerWhat the user sees
Final answerReply with no tool callsThe answer
Step limitN model callsBest partial answer, marked incomplete
BudgetTokens or cost over ceilingSame, plus "stopped to limit cost"
TimeoutWall clock exceededPartial result; maybe continue in background
StuckRepeats or no new information"I couldn't find X; here's what I tried"
Fatal errorAuth failed, dependency down after retriesWhat failed, what was done, what to try
Needs approvalPolicy says askPause with an approval card; resume later
InterruptedUser cancels or sends a new messageAcknowledge; keep or discard work as agreed
PolicyGuardrail or permission deny on a required stepExplain the limit; offer an alternative

Record the reason

Return a structured result: {answer, stop_reason, steps, cost}. Stop reasons are one of the most useful metrics you have: a rise in step_limit or stuck stops is an early warning.

Pausing is not stopping

Approval and interrupts should persist state so the run can continue. Treating them as errors loses work.

Follow-ups

  1. L2. Why not rely only on the model deciding it's done?

    Expected answer

    Models loop, wander or give up early; guards bound cost and time regardless of model behaviour.

  2. L2. What should a forced stop do with the work so far?

    Expected answer

    One last model call asking for the best answer with available information, flagged as incomplete, or a structured summary of progress.

  3. L3. How do stop reasons feed evaluation?

    Expected answer

    Track their distribution per release; regressions show up as more limit hits before success rates move.

Wrong answers interviewers hear
  • "When the model says it's done." That's one stop; without guards a confused model never stops.
  • "A step limit is enough." Steps don't bound tokens, time or money.
  • "On any error." Most errors should be observations the model can recover from.

Taught in

Improve this answer