↑ Resources / Technical

Detecting AI Agents Stuck in a Loop

Technical · 6 min read ·

Some agent failures are quiet. A loop is not. The agent calls the same tool with the same arguments, gets a result it does not accept, and calls it again. Each attempt costs a model call and a tool call. Left alone overnight, a loop shows up as a stuck job, a duplicated order or an invoice from your model provider.

This guide covers why agents loop, why the obvious way of counting repeats does not work, and how to detect a loop early without reading what the agent said.

Why agents get stuck

Loops have a few common causes, and most are ordinary:

  • A tool that keeps failing the same way. The API times out or returns an error the agent does not understand, and it retries without changing anything.
  • A result the agent cannot recognize as done. The task succeeded, but nothing in the response tells the model so, and it submits again.
  • A plan that circles. Two steps that each undo or invalidate the other, so the agent alternates between them.
  • Manipulation. Less often, injected instructions can push an agent into repeating an action on purpose.

Retries are not a bug in themselves. Agents are supposed to recover from transient errors. The problem is repetition without progress.

Why counting repeats is the wrong measure

The first idea is usually to count how often each tool appears in a run and alert above a threshold. In practice this flags almost every agent. Agents search, read, search again and read again as part of normal work. Calling the same tool many times in one run is exploration, not a failure.

Two details make the signal useful. First, compare the arguments, not only the tool name: searching for five different things is work, searching for the same thing five times is not. Second, count consecutive repeats, not repeats anywhere in the run. An agent that comes back to a call later has usually learned something in between. An agent that makes the identical call three times in a row has not.

Detecting a loop without reading content

Comparing arguments seems to require reading them, which many teams do not want a monitoring service to do. A hash avoids that. The agent or its instrumentation computes a digest of each tool call's parameters and sends only the digest. Two identical calls produce the same digest. Nothing about the content can be recovered from it.

With the tool name and a parameter digest on every call, a loop becomes a simple, deterministic rule: the same tool with the same digest, called back to back within one run. It needs no learning period and no model to judge it, so it works from the very first run.

How Kyde Score handles loops

  • Kyde Score counts consecutive calls with the same tool and the same parameter digest (kyde.args.digest) within one run.
  • From the third identical call in a row it raises a loop alarm, and the agent's score is capped at watch.
  • From ten identical calls in a row it treats the loop as runaway, and the score drops to deviating.
  • Loop detection does not wait for a baseline. During an agent's learning phase, a runaway loop sends a direct alert by webhook and email.

Two limits are worth stating. Without a parameter digest on the call, Kyde does not count repeats at all, because it cannot tell an identical call from a legitimate second call to the same tool. Standard OpenTelemetry instrumentations do not send that digest today, so it has to be added as an attribute on the tool call. And Kyde does not watch your bill: it does not read token counts or costs. It watches the calls that produce them.

A loop alarm tells you an agent is stuck. Ending the run is up to you, or to Kyde Control, the gateway that sits in the agent's path, runs in your own environment and can hold the next call. Compare Score and Control.

KYDE Score

Kyde Score flags an agent that repeats the same call: from three identical calls in a row it raises an alarm, from ten it marks the run as runaway. It works from the first run, reads only a hash of the parameters, and sends a signed webhook when the score changes band.

Score an agent →