Who stops the loop? Limits that act during the run
An agent that loops spends money until something stops it. Which limits act while the run is going, and what to check in any tool before you trust it.

One developer described in a public forum how an agent looped on a broken tool over a weekend. The developer woke up to find that the agent had used a very large number of API tokens. It had called the same broken tool again and again, all weekend, and every call cost money.
Nobody decided to spend that money. Nothing in the run decided to stop.
An agent is a model, instructions, tools and steps (see what an AI agent is). A loop lives in the steps. This article is about the limits that act on those steps while the run is still going.
Three reports with the same shape
A user of a workflow tool reported in a public forum that one of their AI workflows got stuck retrying. It quietly used up credits for two days before the user noticed. The bill was one number for the month, so there was no way to tell which workflow had caused it.
Another user reported an agent step with automatic retry switched on. When the agent reached its own step limit, the step did not fail. It started the task again from the beginning, with no memory of the tools it had already called, and the retry count started again too. In one run it restarted 11 times and made 105 tool calls. A second user reproduced the problem. When we read the report, the vendor had not confirmed it.
A third developer wrote in a public forum that most of their budget overruns had one cause: a loop that retried the same broken tool call. Their own fix was to end the run after three failures of the same tool call with the same arguments. That ends the run long before any spend cap is reached.
In all three, the money went on one small step, repeated, while nothing in the run counted.
A spend cap acts too late for a loop
A spend cap at your model provider is useful, but it usually counts by the day or the month, and a loop works by the second. When the cap acts, the money is already spent, and the cap does not tell you which run or which step spent it.
The limits that help with a loop sit inside the run. They count what the agent does, step by step, and they stop it where it is. They live in the harness, the layer around the model that runs your agents, not in the model. You can ask a model in its instructions to stop after three tries. Only the harness can count the tries. For who checks the harness itself, see who audits the harness.
For what an agent costs, and how to see it, see AI agent cost control.
What to check in any tool, ours included
Ask these about the version you would install. Ask to see each limit on a real agent, and ask who sets it. Our own answer follows each question.
Can I limit iterations, tool calls and failures in a row? EpicStaff: yes. A builder sets, per agent, the maximum number of iterations, tool calls and consecutive failures; the agent stops when it reaches one.
Is there a limit on the flow as a whole, so a loop between steps ends? EpicStaff: partly. A builder does not set a loop count for a flow, but a fixed step limit stops endless loops.
Can I limit how long one agent works on its task? EpicStaff: yes. Each agent has a "Maximum Execution Time" setting, in the screen and in the API.
Can I limit how long one tool call takes? EpicStaff: yes, with the "Tool Timeout" setting, in the screen and in the API. When it fires, that tool call fails and the agent is told; the agent itself goes on.
Can I limit how long a run lives? EpicStaff: yes. Each flow has a run lifetime, set through the API only, not in the screen. EpicStaff stops a run that goes past its time limit and marks it expired.
Can I give a run a token budget? EpicStaff: yes. A run can carry a token budget, set per run through the API, or for the whole installation by the operator. It is off unless someone sets it. The count is taken after each step, so the run stops after the step that uses it up. The run then gets the status "stop", and the reason is stored.
Can a person stop one run now? EpicStaff: yes. EpicStaff calls a run a session. The stop button in the session list, on the all-sessions page and in the running-flow view stops it, and the API can do the same. The run gets the status "stop", and its finish time is recorded.
Can I see what each step used? EpicStaff: yes. EpicStaff records the tokens each step used, and the total for the run.
Can an agent hand work to another agent outside the flow I drew? EpicStaff: no. An EpicStaff agent cannot hand work to another agent on its own; work moves from one agent to the next only along the steps the builder draws in the flow.
When a limit acts, look in the record
A limit that stops a run does half the job. The other half is knowing that it stopped, and why.
When a run hits its token or time limit, EpicStaff stops it; the reason is stored, but the screen does not always say a limit was hit. When an agent stops at a limit, the run record shows which limit and why. So check the stored run record, not only the status on the screen. For runs that end without saying what went wrong, see silent failures in AI agents.
A test loop on a quiet day
You do not need an incident to learn how your limits behave. You can make one on purpose.
Pick the agent that runs when nobody is watching: at night, at the weekend, on a schedule. Write down every limit it has, and who set each one. Then copy the agent, give the copy a tool that always fails, and run it. Note which limit stops it, how long that takes, how many tokens it used, and where the reason shows up. If nothing stops it within the time you would accept, you know which field to fill in first.
Then name the person who presses stop, and agree how that person hears that a run needs it.
Start this week, with the agent that runs at night.
Questions & Answers
How do I stop an AI agent from looping?
Give the agent limits that a program counts, not a request in its instructions. Useful limits are a maximum number of tool calls, a maximum number of failures in a row, and a time or token limit for the whole run. Make the first limit that acts a small one, so that a loop ends after minutes, not days.
Why does a spend cap not stop an agent loop?
A spend cap at a model provider usually covers a whole account, by the day or the month. A loop can spend a large amount well inside that cap, and the cap cannot tell one stuck run from a busy day of normal work. A limit on the run itself can, because it counts only what that run does.
What should I test before an agent runs unattended?
Test what happens when things go wrong, not only when they go right. Give a copy of the agent a tool that always fails, a tool that is slow to answer, and a task it cannot finish. For each test, check which limit stops the run, how much it used, and whether the stored record says why. Also check that the person who must press stop hears about it.
In EpicStaff, what stops a run that goes on too long or uses too many tokens?
Each flow has a run lifetime, set through the API only. EpicStaff stops a run that goes past its time limit and marks it expired. A run can also carry a token budget, set per run through the API, or for the whole installation by the operator; it is off unless someone sets it. The count is taken after each step, so the run stops after the step that uses it up, with the status "stop" and the reason stored. A person can also stop a run with the stop button, and the API can do the same.
