AI Agent Infinite Loops: Step, Cost and Stop Caps for Company Systems
A practical guide to step caps, cost caps and stop conditions that halt a looping AI agent before it damages company systems, with checks owners can run.

An AI agent infinite loop happens when an agent keeps calling models and tools without reaching a finished state, and the company systems it touches absorb the cost. The fix is to set three limits before the agent runs live: a maximum number of steps per task, a maximum spend per run and per period, and explicit stop conditions that halt the run when progress stops or writes go wrong. Caps limit the damage, stop conditions end the loop, and the halt leaves a readable record for an owner to review.
Key takeaways
- A loop is rarely infinite in the strict sense. It is usually a retry or re-plan that repeats without progress, and it can run long enough to do real damage.
- Put a step cap, a cost cap and a write cap on every agent run, sized to the task rather than to a generic default.
- Stop conditions should examine state, such as repeated identical tool calls or steps that add no new information, not only counters.
- When an agent halts, stop writes first and keep memory, queue and logs so the run can be inspected and resumed safely.
- Give one named owner every halt notice and the authority to adjust the limits from logged evidence.
Why a looping agent does damage before anyone notices
A looping agent rarely looks broken from the outside. It keeps producing activity: model calls, tool calls, drafts and status updates. A common pattern starts with a tool returning an ambiguous error. The agent retries with slightly changed arguments, the retry creates a partial record, and the agent reads that record as new evidence and tries again. Each step looks reasonable on its own. The damage accumulates as duplicated tickets, repeated messages to customers, a field overwritten many times in a CRM, and model usage that nobody approved.
Two failure modes need different controls. Runaway cost is about spend across calls. Runaway action is about the same effect being produced again and again on company systems. A token limit does not stop an agent that sends one email per iteration at low cost, and a write limit does not stop an agent that burns through a large model budget while reading documents. You need both. OWASP's Top 10 for LLM Applications lists unbounded consumption as a distinct risk, which is a useful reminder that loops are an operations and security concern, not only a quality problem.
Set a step cap for every run
Define a step as one model call or one tool call, and write that definition into the agent's specification so everyone counts the same way. Then set the cap per task type. A lookup that reads one record and drafts a reply needs far fewer steps than a reconciliation that touches several systems. Do not guess the number. Run the agent in shadow mode or against a sandbox, record how many steps successful runs took, and set the cap above the high end of normal successful runs while staying well below the point where damage starts. The shadow pilot approach is described in run an AI agent in shadow mode before giving it authority.
When the cap is reached, the agent should not retry. It should stop, save its state and write a short reason: which step it reached, which tool it was using and what it was trying to achieve. A halt with a clear summary is worth more than a cap that silently drops the task, because the summary tells the owner whether the task was impossible, ambiguous or simply large.
Set cost caps per run, per workflow and per period
Use three spend ceilings. The per-run ceiling catches a single loop. The per-workflow ceiling catches a prompt or tool change that makes every run expensive. The per-period ceiling catches slow creep that no single run reveals. The finance owner should set the amounts based on what a completed task is worth to the business, not on what the model provider allows. Measuring cost per completed task rather than cost per message is what shows whether a cap is too tight for real work or too loose to matter.
Write caps deserve the same discipline as spend caps. Set a maximum number of records changed, outbound messages sent and external bookings or payments initiated per run. These caps protect customers and data, and they should be lower than the step cap, because a write is harder to reverse than a model call. A good default for the first live period is a write cap of zero, with a person approving each write, and then a small number raised only after the logs show clean runs.
Stop conditions that check progress, not only counters
Counters are blunt. A run can hit its step cap while making real progress, or stall in a few steps while spending heavily on retries. Stop conditions look at what the run is doing. Use this decision guide when you write them:
- The same tool is called twice in a row with identical arguments: halt, report, and do not retry.
- The same error class comes back repeatedly within one run: halt and route the task to a person.
- Two consecutive steps add no new information to the run's working context: halt and summarize what was tried.
- The next planned write would exceed the run's write cap: halt before the write, not after.
- A required field is still missing after a retry, or the output breaks a rule in the agent's instructions: halt and escalate.
- The external service returns throttling responses: pause and back off instead of calling again.
Anthropic's guidance on building effective agents describes bounded loops with explicit stopping conditions, which is the same principle at a smaller scale. Test each rule before trusting it. Replay a loop from your logs, or a deliberately broken test case, and confirm that the halt fires at the right moment and not earlier. A rule that never fires in testing is either correct or untested, and you cannot tell which until you try it. For a closer look at detecting repetition, see AI agent stuck in a loop: stop conditions that actually work.
Halt safely: stop writes first and keep the state
When a cap or stop condition fires, the first action is to stop further writes and outbound messages. Read-only work can pause or continue, but the system should not keep changing records while people decide what happened. Keep the working memory, the task queue and the logs intact. A halt that clears the state forces a restart from zero and erases the evidence the owner needs. For a broader pause that keeps queues and memory in place, see AI agent kill switch: pause writes without losing memory or queue.
Resume only after checking the run for partial writes. Retries after resume should use operations that are safe to repeat, so that a second attempt updates the existing record instead of creating another one.
Illustrative scenario: an agent drafts payment reminders for overdue accounts. One date field returns an error in the billing system. The agent retries with a reformatted date, and each reformatted attempt creates a new reminder record. The write cap stops the run after a small number of records, and the halt summary lists those records and the step where the retries began. The operations lead removes the duplicates in the billing system, and the agent is changed to validate dates before any write. The write cap limited the duplicates to the number it allowed, and the summary made the cleanup a short task.
A rollout plan for caps and stops
Use this sequence before the agent's first live run:
- List every tool the agent can call and mark each one as read, draft or write.
- Set the write cap to zero for the first live period, or require a person to approve each write.
- Record step counts and spend for shadow runs, then set step and cost caps above normal successful runs.
- Write at least three stop conditions: a repeated-call rule, a repeated-error rule and a no-progress rule.
- Replay a real or constructed loop from the logs and confirm each rule fires at the intended point.
- Name one owner who receives every halt notice and has authority to resume or retire the agent.
- Review every halt on the same working day during the early period, then move to sampled review once halts are understood.
- Change a limit only with logged evidence, and record the reason for each change.
The weekly maintenance checklist for managed AI agents is a useful companion once the agent is live, because it puts limit reviews into a routine rather than leaving them to memory.
Who owns the limits after launch
Caps drift. Model prices, tool responses and business volume change over time, so a limit that fit the first week may halt normal work later or fail to stop a real loop. Someone has to review halts, adjust limits and check permissions on a schedule. The NIST AI Risk Management Framework is a useful reference for assigning those responsibilities and recording decisions about risk.
Be Human's managed approach treats this as part of operations. The team defines the agent's role, memory, tools and approval boundaries, then sets step, cost and write limits against an observable success criterion. Monitoring tracks spend and halts, recurring evaluations check whether the agent still completes real tasks, permission reviews confirm that write access stays narrow, and incident response covers the cases where a limit is hit and the cause is not obvious. Every change to a limit is logged and reviewed rather than made quietly.
If you want to find the first task worth handing to an agent, the free Be Human AI diagnostic is a practical place to start.
Frequently asked questions
How many steps should an agent be allowed per task? There is no universal number, because the right cap depends on the task and the systems involved. Derive the cap from successful shadow runs, place it above the normal high end, and keep it well below the point where a loop would cause damage. Revisit it whenever the task or its tools change.
Is a token budget enough to stop a loop? No. A token budget limits cost, but it does not stop an agent from repeating a write to a company system while staying under budget. You need write caps and stop conditions that examine what the agent is doing, alongside spend limits.
What should happen to work in progress when a cap fires? The agent should stop further writes, keep its memory, queue and logs, and produce a short summary of the steps it took and the reason for the halt. Resume only after checking for partial writes, and use operations that are safe to repeat so a retry does not create a duplicate record.
Who should own the stop rules? A named business owner should decide the limits and receive halt notices, while a technical owner implements and tests the rules. Be Human's managed operations can handle monitoring, limit reviews and incident response, but the business owner still decides what the agent is allowed to do.
Your next step
See where an AI agent fits in your company first.
Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.
Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.


