An agent loop is designed to run until the model returns no tool calls. During a stress test, the loop executes 200 iterations on a complex task without terminating. The model continues generating tool calls indefinitely. What termination conditions should the architect add to prevent infinite loops?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — b is correct because robust agent loop termination requires multiple independent guards rather than relying on a single condition. An iteration counter catches infinite loops directly; a time limit catches loops where each iteration is slow; detecting repeated identical tool calls catches the specific pathology of a model oscillating between the same two actions without progress.
Full explanation below image
Full Explanation
B is correct because robust agent loop termination requires multiple independent guards rather than relying on a single condition. An iteration counter catches infinite loops directly; a time limit catches loops where each iteration is slow; detecting repeated identical tool calls catches the specific pathology of a model oscillating between the same two actions without progress. Combining these three makes the termination logic resilient to different failure modes. C is wrong because tracking cumulative input tokens is useful for context management but not as a primary termination mechanism; a loop making short tool calls could execute thousands of iterations without approaching the context limit. A is wrong because instructing the model to 'stop after completing the task' is already implied by normal agent design and evidently insufficient when the model cannot determine task completion; a 1,000-iteration fallback is dangerously high and would cause severe cost overruns before triggering. B is wrong because routing every tool result through a secondary evaluator model doubles the API call overhead and adds latency per iteration; it is over-engineered for what is fundamentally a loop control problem.