Zenaique

Which of the following are canonical stopping conditions for an agent loop?

Multi-select·Medium·4.0 · 0·~1 min·Asked atIntelLlamaIndexOracle·Relevant atAnthropic
Attempt it
TL;DR

Canonical stops are a final-answer signal, a step budget, and a cost or time budget. Tool-count and logit-confidence are not real termination conditions.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine giving a kid a treasure hunt. They keep going until they find the treasure, that is the happy ending. But you also need backup rules so they do not wander forever. So you say: stop after twenty clues, or stop when you have spent all your allowance, or stop when it is dinner time. Those backup rules do not care whether the kid is smart or close to the answer. They just count steps, money, or minutes and call time. A bad rule would be stop once you have touched every tool in the shed, that has nothing to do with finishing. Another bad rule is stop when you feel ninety-nine percent sure, because a confident kid can be confidently wrong. An agent loop works the same way. It stops on success or on a hard limit, never on a vibe.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

A stopping condition is the predicate the agent runtime checks at the end of every loop iteration to decide whether to terminate or run another turn. It is the single most important safety property of the loop, because an agent is by construction a while-loop around a non-deterministic model. Get the stop wrong and you ship either a system that quits before the job is done or one that spins until it drains a budget.

The mental model worth carrying into the interview is that termination has exactly two legitimate shapes. Either the agent has reached its goal and says so, or some external resource limit forces a halt. Every valid stopping condition reduces to one of those two. Anything that does not is a distractor, no matter how technical it sounds.

This question is a select-all, and the discipline it tests is separating real termination criteria from things that merely sound rigorous. The three correct answers, final-answer signal, step budget, and cost or time budget, are the conditions every production framework implements. The two distractors, tool-count and logit-confidence, are plausible-sounding traps that map to no real notion of task completion.

The deeper lesson is that you never rely on a single condition. You pair a goal check with at least one hard cap, because the goal check depends on the very model whose reliability you cannot guarantee.

The success exit: the final-answer signal

The happy-path stop is agent-controlled. The model decides the task is complete and emits a designated termination signal, which is implementation-specific. In function-calling frameworks it is a structured done action or the absence of any tool call. In the Anthropic SDK it surfaces as a stop_reason of end_turn. In ReAct-style agents it is a final-answer line in the trace.

This exit is essential but fundamentally untrustworthy on its own. The model is a stochastic predictor, not an oracle about its own state. A confused agent can declare completion prematurely after a hallucinated assumption, and a stuck agent may never declare completion at all.

That is why mature systems verify the signal rather than accepting it blindly. A common pattern runs a second deterministic check, or a separate judge model, against the original goal before honouring the done signal. If the check fails, the loop continues. This converts a soft, model-controlled exit into something closer to a real acceptance test.

It also matters how you represent the signal. Relying on the model to emit a free-text phrase like done is brittle, because the same model that hallucinates an answer will hallucinate the phrasing. Function-calling frameworks make the signal a typed action with a schema, which the runtime can detect deterministically. The detection is then reliable even when the judgment behind it is not, and those are two separate problems you want to keep apart.

The runtime backstops: step and cost budgets
Why the two distractors fail
Beyond the canonical three
Putting it together: the select-all discipline
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
ConditionWho controls itValid stop?Why
Final-answer signalAgentYesDesignated done token or action marks task complete
Step budgetRuntimeYesHard cap on iterations, the primary backstop
Cost or time budgetRuntimeYesBounds token spend and wall-clock latency
Tool count usedRuntimeNoCoverage of tools is unrelated to goal completion
Logit confidence over 0.99AgentNoToken probability is not calibrated to task success

Real products, models, and research that use this idea.

  • LangGraph's prebuilt ReAct agent exposes a recursion_limit on the state graph that hard-caps iterations independently of whether Claude Opus 4.7 or GPT-5.5 signals a final answer.
  • The Anthropic SDK agent loop terminates when the model returns a stop_reason of end_turn (final answer) and pairs that with a caller-side max-steps guard.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QBeyond the three canonical conditions, what other stopping signals do production loops add?
A

Discuss repeated no progress detection that hashes recent actions, an explicit human-stop or approval gate before high blast radius actions, and verification of the final answer before accepting it. Explain why each catches a failure the basic three miss.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Picking confidence score because it sounds rigorous. Token logits are not calibrated task-success signals, so a high probability says nothing about whether the agent actually finished the job.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Name the three canonical stopping conditions for an agent loop.

  • Explain which conditions the agent signals versus which the runtime enforces.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the Model Context Protocol (MCP) and what problem does it solve?
MCQ·Easy