OpenRouter Guide Offers Four Controls for AI Agent Loops
OpenRouter published a guide for stopping AI agents from repeatedly calling a failing tool. It recommends doom-loop detection, a rule for identifying repeated calls, per-run step and cost caps, and an API-key credit limit. The first three controls are available through version 0.11.0 of the OpenRouter Agent SDK, while OpenRouter enforces the key limit. In OpenRouter’s tests across six models, all six were blocked on their third identical tool call when detection was enabled. Without detection, 4 of 18 runs retried until a 40-step cap; with it, 16 of 18 runs ended after two real tool calls. Exact-match detection can miss loops that slightly change arguments, which the guide addresses with normalized loop keys.
The four controls address different failure modes: repeated-call detection, argument normalization, per-run limits, and provider-side spending limits. OpenRouter’s tests provide implementation examples for limiting runaway tool calls and costs.
How to Stop an AI Agent Stuck in an Infinite Loop
OpenRouter ·11/12/2026


An AI agent gets stuck in an infinite loop when a model keeps calling a tool that fails, usually with the same arguments, because nothing in the agent loop tells it to stop. Each retry resends the whole conversation, so every turn costs more than the last, and a loop left running overnight can cost thousands of dollars.
This guide stops the loop with four guards, which we tested on six current models. Three run inside your agent through the OpenRouter Agent SDK (@openrouter/agent 0.11.0): doom-loop detection, a rule for which calls count as repeats, and caps on steps and cost. The fourth is a credit limit on your API key. We enforce it on our side, so it holds even when your agent code has a bug.