# OpenRouter explains four guards that stop AI agents looping on failing tools

> Original title: How to Stop an AI Agent Stuck in an Infinite Loop

- Source: OpenRouter Blog
- Published: 2026-11-12T00:00:00.000Z
- Bad Influence: https://badinfluence.news/items/i0snl9zl7skl3gld0qe2o6ddt
- Original: https://openrouter.ai/blog/tutorials/ai-agent-infinite-loop/

## Summary

OpenRouter says an AI agent stuck retrying a failing tool call can rack up thousands of dollars, and its guide stops the loop with four guards tested on six models. Three run through the OpenRouter Agent SDK (@openrouter/agent 0.11.0): doom-loop detection, a rule for which calls count as repeats, and step and cost caps. The fourth is a credit limit on the API key, which OpenRouter enforces on its side so it holds even if agent code has a bug.
