Stop runaway AI: limits on steps, time and spend
Key takeaways
- Set hard limits on steps, time, spend and repeat messages for every job an AI agent does.
- Put the limits in the code that runs the agent, not in its instructions, where a stuck agent can lose track of them.
- When a limit is hit, stop, explain and hand over to a person. Never retry automatically.
Short version: give every AI agent hard limits on how many steps it may take, how long it may run and how much it may spend, and set them in the code that runs it, not in its instructions. When it hits a limit, it should stop, say what it was doing and hand the job to a person. It should never quietly try again.
What runaway AI looks like in a small business
An AI agent is an AI that works through a job in steps: read the message, look something up, decide, do the next thing. Most of the time it finishes in a handful of steps. Occasionally it doesn’t.
- It can’t find an order, so it searches again, and again, slightly differently each time.
- Two automations set each other off: one sends a reply, the other treats the reply as a new message.
- A customer sends a very long thread, and the agent reads all of it on every step.
Nothing dramatic happens. It just keeps going, using up time and paid usage, and sometimes sending the same customer the same message more than once.
AI agent guardrails that actually hold
The tempting fix is a line in the instructions: “Don’t take more than ten steps.” That isn’t a limit. It’s a request, and an agent stuck in a loop is exactly the kind of agent that loses track of requests.
A real limit lives outside the AI, in the code or the automation tool that runs it. It counts the steps itself and stops the agent when the count is reached, whatever the agent thinks about it. The same idea runs through Customer messages are data, not instructions: what you rely on should be built in, not asked for.
Which AI agent limits should you set?
- Steps. A maximum number of actions or tool calls for one job. Set it a little above what a normal job needs, so ordinary work never hits it.
- Time. A maximum time for one job to run. If a reply normally takes moments, a job still running after several minutes is stuck.
- Spend. A cap on paid usage per job and per day, set in the AI provider’s account as well as in your own code. Two locks are better than one.
- Repeats. A limit on how many messages go to the same customer in a short period. This one catches loops the others miss, and it protects your reputation as well as your bill.
You don’t need the perfect settings on day one. Start tight, watch what normal jobs need for a couple of weeks, then adjust.
When an agent stops due to max iterations
Many automation tools show a message along the lines of “agent stopped due to max iterations”. It means the agent hit its step limit before finishing. That’s the limit doing its job, not the tool being broken.
What matters is what happens next. A good set-up does three things:
- Stops cleanly. No half-sent reply, no half-made change.
- Says what it was doing. The job, the customer, the last few steps and why it was stopped, written somewhere a person will see it.
- Hands over. The job goes into the queue for a person, marked as stopped by a limit.
What it must not do is retry automatically. A job that ran out of steps once will often run out again, and an automatic retry turns one stuck job into a loop of them.
How to stop an AI agent getting stuck in a loop
- Don’t let automations answer each other. Mark the messages your own systems send, and have the agent ignore them.
- Give it a way to give up. Make “I can’t do this, passing it to a person” a normal, easy outcome rather than a failure it avoids.
- Read the stopped jobs. If the same kind of job keeps hitting a limit, the job is badly defined or a tool is broken. Fix that rather than raising the limit.
- Keep the big off switch too. Limits handle one stuck job. For everything going wrong at once, you need to stop the lot in minutes. See Every AI needs an off switch.
Say you sell garden planters online and an agent answers delivery questions overnight. With a step cap, a time cap, a daily spend cap and a repeat limit in place, the worst a stuck job can do is stop and wait for you in the morning. That’s a much better start to the day than finding one customer has had the same email a dozen times.
Want to see which jobs in your business are worth handing to AI, and which aren’t? Grafto’s AI Tools Report works it out from a short questionnaire.
Frequently asked questions
What are AI agent guardrails?
Rules built into the system around an AI agent that it can’t talk its way past: which tools it has, how many steps it may take, how long it may run and how much it may spend. Instructions in the prompt are requests, not guardrails.
What does agent stopped due to max iterations mean?
The agent hit its step limit before finishing the job. That’s the limit working. The job should go to a person with a note of what the agent was doing, rather than being retried automatically.
How do I stop an AI agent getting stuck in an infinite loop?
Cap its steps and running time in code, stop your own automations replying to each other, limit how many messages one customer can receive in a short period, and give the agent an easy way to hand over to a person.
Questions, or want a tool we don't have yet? Email hello@grafto.co.uk — a real person replies.