Your AI Called the Same Tool 41 Times for One Invoice. Four Gates That Stop It.

Published on: 2026-11-13

One invoice. Forty-one calls. That is a demo from an OpenRouter tutorial: a billing assistant whose only tool fetches invoices. The backend kept timing out, returning the same thirty-second error every time. The agent called that tool forty-one times with the same invoice number, spent three cents, and then wrote, in its final answer, that the service had been timing out all along.

It is not stupid. From where it stands it is doing exactly the right thing: the task is unfinished, the tool errored, try again. An agent loop has one termination condition, which is that the model stops requesting tools. If the tool keeps failing, the model has no reason to stop.

Why idling gets expensive

📖 Glossary

AI Box (also known as Agent Computer / Agent PC), is a dedicated local hardware device that runs AI Agents. Pre-installed with an AI agent management system, plug-and-play, running 24/7. Users can remotely command AI to work via Discord, Slack, Telegram, WhatsApp, and more.

Every round resends the entire conversation, including every failure before it. The tutorial measured input tokens climbing from 131 to 3,262 inside a single session. Each round costs more than the last, and the more failures pile up, the more the next round costs. Nothing here is a bug in the model. It is a missing stop condition in the design.

Four gates, one class of loop each

KAIHE AIBOX 概念产品与 IDLE LOOP 全息任务面板

The first gate recognises duplicates. It fingerprints the tool name plus its arguments, returns an error at the third identical call and ends the session at the sixth. That is one line of configuration. What it catches precisely is the same tool with the same arguments, again and again. What it misses is a model that renames the invoice number slightly on every attempt.

The second gate flattens small differences in arguments, because models will quietly vary a parameter to escape a fingerprint. In the tutorial, Mistral Large 4 did this in five of nine runs by alternating an uppercase and lowercase invoice number, and GPT-6 Luna used trailing spaces and newlines. Normalise case, spacing and prefixes, and the fingerprint finally holds.

The third gate caps steps and money at the same time. A normal task runs four to six rounds, so the tutorial set fifteen steps and one cent. There is a trap here: a cap of five executes six calls, and a cap of forty executes forty-one, because the closing turn still runs one more tool call.

The fourth gate lives on the server. Give every agent its own API key with a dollar limit and a reset period. The tutorial demonstrates it: a key holding $9.97 rejects a request for 900,000 max tokens outright, replying that it can only afford 664,657. Of the four gates, this is the only one that runs outside your code.

They do not stop the same thing

Same call, same arguments: the first gate is enough. Same call, arguments shifting: only the second gate catches it. A fresh approach on every round: the first two miss it entirely, and only the cost cap in the third gate holds. A hundred sessions that each stay under budget: only the fourth gate sees the total. A deployment where someone forgot to configure anything: again only the fourth gate.

So the conclusion is not "install one and move on." Four different shapes of runaway need all four layers.

One clean test proves nothing

With identical input, Grok 4.7 called the tool 41 times, then 12, then 41 across three runs. That variance is the part worth remembering. A loop is not a property of your codebase; it is a behaviour that appears depending on how the model happens to respond that day. If you have not been hit yet, it may only mean you have not been hit this time.

Six models, three runs each, eighteen runs in total. With no protection at all: 314 tool calls, $0.29, and four runs hitting the forty-step cap. With only the first gate on: 64 calls, $0.05, and sixteen of eighteen runs stopping after two real calls.

Four things you can do tonight

KAIHE AIBOX 概念产品与 STOP THE BILL 全息信息层

Look through last week for any single session with more than ten tool calls. Check whether input tokens climb steadily within one session. Give each agent its own key with a daily limit. And take "retry until it succeeds" out of your prompt, replacing it with "after two failures, stop and tell me."

What it does not guarantee

Four gates buy you control, not the cheapest possible bill. A cap will occasionally kill a legitimately heavy task, so the number should come from your own normal round count. The server-side limit is the last line, and by the time it fires, some money is already spent. One more thing deserves saying plainly: where the machine sits changes none of this. A local deployment can idle just as happily as a cloud one.

Why visibility is the starting point for us

This is why KAIHE AIBOX(铠盒AIBOX)treats running on your own machine as a first-class requirement rather than a slogan. The real cost of a runaway agent is not the money. It is that you had no idea it was still spinning. When the machine sits on your desk, every tool call happens somewhere you can watch, and you can cut it off the moment it looks wrong.

Running around the clock only means something if you can stop it at any moment.

Recommended Products

A1 Home Entry A1 Pro Enhanced A2 Professional A2 Pro Advanced X1 Enterprise G1 Flagship
© KAIHE AI - Agent Computer Specialist