# Does the model or the tool decide when an agent loop ends?

Either can be the thing that never stops. Across the 68 confirmed infinite agentic loops in a study of 6,549 open-source agent repositories (arXiv:2607.01641), 28 (41.2%) were tool-controlled retry and 26 (38.2%) were model-controlled termination. The categories overlap, so they add up to more than 68, and 23 loops had no exit at all.

A concrete case from the paper: a planner calls the model until the reply parses. Parser errors are swallowed, and a rejected plan resets the success flag, so execution returns to the same model call with no retry cap, timeout, or token budget on the path. The loop ends only if the model eventually produces output the code accepts.

The authors advise against relying on the model to eventually stop producing tool calls, valid plans, or termination messages. For how much a retry limit covers, see [whether a retry limit stops an agent looping](/answers/agent-loops-research/does-a-retry-limit-stop-an-agent-from-looping-forever). [Tool failures](/answers/tool-calling/what-are-the-ways-a-tool-call-can-fail) are one source of that output. The counts describe code in public repositories, not how often these loops run.

---

Sources:
- Hou, Wang, Zhao, and Wang, "When Agents Do Not Stop" (arXiv:2607.01641), Table II and Figure 6: https://arxiv.org/abs/2607.01641 (fetched 2026-10-27)

Source: https://tessary.ai/answers/agent-loops-research/does-the-model-or-the-tool-decide-when-an-agent-loop-ends
More on Agent loops research: https://tessary.ai/answers/agent-loops-research
From Tessary, agent reliability for AI agents in production: https://tessary.ai
