Loop Guards for Superintelligent Agents: Stop Stuck Runs Early
Learn how to stop a stuck AI agent run early with repeated-state detection, step caps and timeouts that hand the task to a person with a clear reason.

An AI agent gets stuck when it repeats the same action, retries a failing tool without making progress, or keeps reasoning without reaching a result. A loop guard is a set of checks that watches each run, halts it when progress stops, and hands the task to a person with a stated reason. Three controls do most of the work: repeated-state detection, step caps and timeouts, each tied to a clear halt message.
Key takeaways
- A stuck run usually looks busy from the outside, so guards must measure progress, not activity.
- Repeated-state detection catches agents that take the same step again with the same inputs and results.
- Step caps, tool call limits and wall-clock timeouts stop runs that drift without repeating themselves.
- Every halt should produce a handoff note that says what was attempted, which guard fired and what decision is needed.
Why agent runs loop in the first place
A loop rarely starts from a dramatic failure. It usually starts with something small: a tool returns an empty result that the agent reads as a reason to search again, a field in memory is never updated so the same question keeps reappearing, or two instructions pull in opposite directions and the agent alternates between them. Each step looks reasonable on its own, which is why a loop can run for a long time before anyone notices.
Three patterns cause most of the trouble in business workflows. The first is ambiguous tool output, where the agent cannot tell whether an action succeeded and tries it again. The second is missing stop conditions, where the task has no defined end state the agent can recognize. The third is retry logic without change, where the same request is sent with the same arguments after each failure. Guards are designed for these patterns, so it helps to name which pattern you expect for each workflow before you choose limits.
Guidance on building agents, including Anthropic's notes on building effective agents, consistently treats clear stopping conditions and bounded tool use as part of the design, not an afterthought. The practical question for an operations leader is simpler: if this agent stops making progress at two in the morning, what will stop it, and who will know?
Repeated-state detection: recognize when nothing changes
Repeated-state detection asks a narrow question on every step: have we been in this situation before? In practice, the run builds a fingerprint of each step from the action name, the normalized arguments and a short summary of the result. Timestamps, request identifiers and other values that change on every call should be removed before fingerprinting, otherwise the guard never sees a repeat.
Two patterns deserve attention. The first is an exact repeat, where the same fingerprint appears again within the same run. A single repeat can be legitimate after a transient error, so the usual rule is to allow one retry and halt on the second identical fingerprint. The second is oscillation, where the run alternates between two or three states without ever leaving that cycle. Keeping a short window of recent fingerprints and checking for both patterns catches most loops that a simple counter would miss.
The fingerprint should also include the state the agent is trying to change. If an agent updates a customer record and the record already has that value, the step did nothing useful, and the guard should treat the step as stalled even if the tool call technically succeeded. This is where observability matters: the trace must show the state before and after each action, so that the guard and the reviewer see the same facts. The OpenTelemetry primer on observability concepts describes the traces, logs and metrics that make this kind of inspection possible.
Step caps and budgets: count the work, not the reasoning
A step cap sets the maximum number of actions a run may take before it must stop. It also works as a second line of defense when the fingerprints differ on every step, which happens when an agent keeps searching with slightly new wording. Caps should be set per task type, because a reconciliation task that reads many records needs a different limit than a single reply drafted from a short ticket.
Useful caps usually cover three things: total steps in a run, calls to any one tool, and spend in tokens or currency for the run. The spend cap is covered in more detail in AI Usage Alerts and Hard Stops, which explains how to turn a cost signal into an action. The key point here is that caps count events. They do not ask the model whether it feels finished, because a looping model often feels confident.
Illustrative scenario: a team uses an agent to match incoming supplier invoices to purchase orders. The agent has a limit of twelve tool calls for one invoice. On one invoice, the purchase order search returns no match, and the agent keeps rephrasing the query with different supplier name spellings. At the twelfth call, the run halts, marks the invoice as unmatched, and sends the search history to the finance reviewer. The reviewer finds that the purchase order was filed under a parent company name. The cap did not solve the matching problem, but it stopped the waste and made the gap visible within minutes.
Set the cap a little above what a healthy run needs. If normal runs regularly touch the limit, the cap is hiding a design problem, such as a missing tool or unclear instructions. Review the caps whenever the workflow or its tools change, and record the change so the next reviewer knows why a number moved.
Timeouts: a deadline for the run and for each step
Timeouts answer a different question: how long is this run allowed to take in wall-clock time? A run-level deadline stops work that is still moving but no longer useful, such as an agent waiting on a slow external system while the customer has already moved on. A step-level timeout stops a single tool call that hangs, which prevents the whole run from freezing.
The harder part is what the timeout reports. A timed-out tool call may have completed on the other side, so the agent cannot assume it failed. Reporting unknown rather than failed keeps the next step honest, and it prevents a retry from creating a duplicate action. The article on agent run timeouts walks through deadline settings for each stage, and the piece on tool timeouts and partial failures explains how to label those outcomes so that reviewers can reconcile them.
For any write operation, the timeout should lead to a check against the system of record, not to a blind retry. If the system cannot be checked, the run should halt and go to a person. Timeouts are most useful when they are paired with idempotent actions, so that a retry after an unknown result cannot repeat the work.
Write the halt reason, then hand off to a person
A halt that says only "stopped" is almost as costly as no halt at all, because the person receiving it must reconstruct the run from logs. A good halt message has a fixed structure: the goal of the run, the guard that fired, the last few steps with their results, what is known to be true, what is unknown, and the decision the person needs to make. Keep it short enough to read in under a minute.
The decision matters most. Someone receiving a stuck run usually needs to choose one of a few paths: approve a manual completion, correct the input and restart, narrow the task, or stop the workflow for review. If the halt message names those options, the reviewer acts faster and the agent does not guess. The principle is developed in human escalation for AI agents, which argues for sending the decision rather than the mess.
- Name the goal of the run in one sentence.
- State which guard fired, with the threshold that was reached.
- List the last three to five steps with their observed results.
- Separate confirmed facts from unknown outcomes.
- Offer the two or three decisions the person can make.
- Attach the run identifier so the full trace can be opened.
Keep the agent's memory consistent after a halt. A run that stops halfway through a multi-part change should leave clear markers about which parts completed, so that the restart does not repeat finished work.
A practical plan for adding loop guards this month
If your agents already run without guards, the safest order is to add visibility first, then limits, then automatic halts. Starting with automatic halts before you can see the traces tends to produce a flood of confusing stops that people learn to ignore.
- Pick one workflow that runs often and has a clear end state, such as invoice matching or ticket classification.
- Log every step with the action name, normalized arguments, result summary and state before and after.
- Review two weeks of runs, or the available history, and mark which runs were stuck, which were slow and which were healthy.
- Set a step cap and a tool call cap for that workflow, placed above the healthy runs you marked.
- Add repeated-state detection for exact repeats and for two-state oscillation.
- Set a run-level deadline and a per-step timeout, with unknown reported separately from failed.
- Write the halt message template and test it by forcing a loop in a staging copy.
- Route halts to a named owner with a response expectation, and review every halt in the first week.
Only after the halts are reliable should you tighten the caps. Each tightening should be recorded so that a later change in behavior can be traced to a specific decision.
How Be Human handles loop guards in managed operations
Be Human designs, implements and operates AI agents with their memory, tools, permissions and approval boundaries under the company's control. For loop guards, that means the guard thresholds are part of the agent's written operating notes, the halt messages are tested before go-live, and the halt queue has a named human owner. In managed operations, the team reviews halts, updates thresholds after workflow changes, reviews tool permissions, and runs incident response when a loop reaches a system of record. The aim is that a stuck run is visible, bounded and handed over with enough context to act, without relying on someone noticing it by chance.
Review guards after every change
Loop guards drift out of date. A new tool can return results in a different format, a model update can change how the agent phrases its searches, and a business rule can make an old cap too tight or too loose. Treat each change to the workflow, its tools or its model as a reason to rerun a small set of known runs, including the stuck ones you recorded earlier, and confirm that the guards still fire at the right moments and only then. Keep the review notes next to the agent's change log so that the next person can see why each threshold sits where it does. If you are unsure which of your workflows should receive these guards first, the free Be Human AI diagnostic can help you find the first task worth handing to an agent.
Frequently asked questions
How do I stop an AI agent from looping forever? Combine three controls: repeated-state detection that halts on repeated fingerprints of the same step, a cap on the number of steps and tool calls, and a timeout for the whole run and for each tool call. Each control should write a halt message that tells a person what happened and what decision they need to make. No single control covers every loop, so the combination matters.
What is the difference between a step cap and a timeout? A step cap counts actions, so it stops a run that takes too many steps, even when each step is fast and different. A timeout measures elapsed time, so it stops a run that waits too long, whether or not it is repeating itself. Many stuck runs trip one of these controls and not the other, which is why production setups use both.
Should a halted agent retry the task automatically? Usually not. A retry after a halt can repeat work that already happened, especially when a tool call timed out and its outcome is unknown. Check the system of record first, and only restart when the completed steps are clear. Write actions should be idempotent so that a restart cannot duplicate an invoice, booking or refund.
How do I know if my loop guards are set correctly? Look at the halts over a few weeks. If healthy runs regularly hit the limits, the caps are too tight or the workflow has a design problem. If stuck runs complete without any halt, the fingerprints or thresholds are missing that pattern. Review the results with the people who receive the halts, because they can tell you whether the handoff gave them enough to act.
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.


