LoopCraft
Sign In

2026-08-18

Every agent loop needs an exit: designing termination conditions that actually fire (2026-08-18)

An agent loop that cannot stop is not a design, it is a bill. This guide covers the three families of termination conditions — resource caps, success conditions, and failure exits — and how to combine them so every run ends on purpose.

Back to Blog

Reading time: 7 min

Ask a team why their loop stopped and you will often get a shrug: it finished, or it didn't, or someone killed it. That uncertainty is the symptom of a loop whose termination was never designed. Termination is not a detail you bolt on after the happy path works — it is part of the loop's shape. A loop has three ways to end, and a reliable design defines all three explicitly: resource caps, success conditions, and failure exits. Resource caps are the backstop: a maximum iteration count, a token or cost budget, and a wall-clock timeout. They are cheap, deterministic, and need no judgement about the task — which is exactly why they can never be your only exit. A loop that relies solely on caps does not finish its work; it runs until the money stops. Set caps generously enough that a healthy run never touches them, and treat any capped exit as an incident worth reading the trace for. Success conditions are the exit you actually want: the evaluator score crossed the quality threshold, the answer passed validation, the plan reports no remaining steps. Two rules make them trustworthy. First, encode them as checks the loop can evaluate mechanically — a checklist, a schema, a comparison — not as a vibe the model reports about its own work. Second, put the success check after the step that produces the artifact, not before it; a surprising number of loops exit 'successfully' on data from the previous iteration. Failure exits are the third family, and the one most often missing: a guardrail violation, a tool that has errored three times in a row, or no progress for N iterations — the loop state is byte-for-byte identical to the state N steps ago. No-progress detection deserves special attention because it is the difference between a loop that fails fast and a loop that rehearses the same mistake until the budget runs out. When a failure exit fires, route to a handler that records what happened, not to silent termination. Whatever the exit, record the reason. Every run should end with one of four labels: succeeded, capped, failed, or interrupted for review. 'Capped' runs that carry a success label are how bad outputs reach production — the loop hit max iterations, returned its last draft, and the caller treated that as a result. If you use dry-run simulation, verify each exit path fires at least once before the loop runs live; an exit that never fires in simulation is a condition that never fires in production. In LoopCraft, termination is wired on the canvas like any other behavior: set the iteration cap and cost budget in the loop settings, attach an evaluator or validation node as the success gate, and use a Condition node plus a no-progress check for failure exits — the trace then shows exactly which exit ended each run. Design the exit first and the loop next. The full toolset is at https://getloopcraft.com — sapsap@qq.com.