Ahmed Doghri Logo Image
Ahmed Doghri

agentbudget

Your agent does not crash when it fails. It looks busy forever, retrying the same broken call while every hard limit sits comfortably unbroken. This is the guardrail that actually notices.

agentbudget, an agent loop and budget guardrail

The Failure That Looks Exactly Like Progress

An agentic loop, plan, call a tool, observe, repeat, has no natural stopping point. Give it a task it cannot quite finish and it will not crash. It will do something worse: it will look busy forever. It retries the same failing call. It bounces between two states. It cycles through three approaches without ever admitting none of them are working, and your step counter and your cost counter both sit comfortably under their limits the whole time, because a stall is not a runaway. It is a very well-behaved waste of money.

agentbudget catches the well-behaved failure too. Hard limits (steps, dollars, wall-clock) stop the obvious runaway. Loop detection catches the sneaky one: it hashes every action-and-observation pair and flags the moment the same transition repeats too many times in a short window, whether or not any hard ceiling was ever close.

One Small Algorithm, No Tuning Curve

Hash the last handful of steps into (action, observation) signatures. If any signature repeats three or more times inside the window, the agent is stuck. No embeddings, no similarity threshold, just exact repeats of the same action producing the same result, because an agent that is truly stuck usually repeats itself in ways that are easy to catch exactly.

The Number

On five simulated agent traces, three genuinely stalled and two that actually complete the task, limits-only catches zero of the three stalls, because none of them ever cross a hard ceiling. Loop detection catches all three, usually within a handful of steps, and it never once false-positives on the two traces that finish the job.

9 tests pass in CI across Python 3.9, 3.11, and 3.13.

Tools Used

Python
Agent Guardrails
Loop Detection
pytest
Ruff
GitHub Actions CI