---
title: "Comment by Ahmet Özel on \"How to Stop an AI Agent From Looping Forever (and Burning Your API Budget)\" | Hashnode"
description: "That quadratic input-token table—10 steps taking 74,000 tokens while 100 steps explode to 6.14 million tokens—makes it crystal clear why unbounded agent loops t"
url: "https://hashnode.com/posts/how-to-stop-an-ai-agent-from-looping-forever-and-burning-your-api-budget-cth0l/6b10f578ae98e533721ce054/comment/6b11158b6ebf934669b75f77"
---

[Discussion](https://hashnode.com/posts/how-to-stop-an-ai-agent-from-looping-forever-and-burning-your-api-budget-cth0l/6b10f578ae98e533721ce054)

Comment [How to Stop an AI Agent From Looping Forever (and Burning Your API Budget)](https://hashnode.com/posts/how-to-stop-an-ai-agent-from-looping-forever-and-burning-your-api-budget-cth0l/6b10f578ae98e533721ce054)

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[4h ago](https://hashnode.com/posts/how-to-stop-an-ai-agent-from-looping-forever-and-burning-your-api-budget-cth0l/6b10f578ae98e533721ce054/comment/6b11158b6ebf934669b75f77)

That quadratic input-token table—10 steps taking 74,000 tokens while 100 steps explode to 6.14 million tokens—makes it crystal clear why unbounded agent loops turn small bugs into surprise invoices. Highlighting that Claude Agent SDK leaves both max\_turns and max\_budget\_usd off by default, and that LangGraph counts super-steps rather than raw model calls, saves engineers from assuming their framework protects them automatically.

Pairing a hard token/USD budget with repeated tool-call detection catches the sneakiest failure mode: an agent stuck calling the same failing lookup with slightly different arguments while staying under a generous wall-clock timeout.

[ZyVOP](https://hashnode.com/@zyvop)

[1h ago](https://hashnode.com/posts/how-to-stop-an-ai-agent-from-looping-forever-and-burning-your-api-budget-cth0l/6b10f578ae98e533721ce054/comment/6b11158b6ebf934669b75f77#reply-6b1141c7a44519e9b68b4c1b)

Exactly. Framework-level limits shouldn't be mistaken for complete cost protection. I'd recommend combining hard token and USD budgets with tool-call limits and pattern-based loop detection. One question: do you prefer enforcing these safeguards inside the agent framework or through a centralized execution layer shared across agents?
