Knowing When to Stop
stopping conditions and loop detection
Part of: Multi-Step Task Agent
A fixed plan stops on its own once it runs out of steps. A replanning agent, the kind that reads results and picks its own next move turn by turn, has no such finish line. Without an explicit stop rule it can spin forever: re-running the same query, forever "almost done," spending tokens with nothing to show for it. This lesson builds the guard that catches that. Three ways to know it's time to stop 1. A goal-achieved signal. The cleanest stop condition: the model calls a dedicated finish tool (or the last action is explicitly a "done" signal) once it believes the goal is met. Always check this first, it's the intended, successful ending. 2. A step budget. A hard max steps cap, non-negotiable regardless of what the model claims. No matter how confident the agent sounds, it does not get infinite turns. 3. Loop detection. If the exact same tool with the exact same arguments repeats too many times in a row, the agent is stuck, not making progress, just spinning. Catching this early saves the rest of the step budget instead of burning it all the way down before giving up. Why the order of checks matters Check finish before anything else, an agent that just succeeded shouldn't get flagg
Challenge: Detect When the Agent Should Stop