Skip to main content

Detect repeated agent steps and stop runaway loops. Python port of @mukundakatta/agent-loop-breaker.

Project description

agent-loop-breaker-py

Detect repeated agent steps and stop runaway loops. Pure Python, zero deps. Python port of @mukundakatta/agent-loop-breaker.

pip install agent-loop-breaker-py
from agent_loop_breaker import detect_loop, should_stop

events = [{"tool": "search"}, {"tool": "fetch"}] * 4
res = detect_loop(events, window=2, repeat_threshold=3)
# LoopDetection(looping=True, pattern="search>fetch", count=4)

if should_stop(events):
    raise RuntimeError("agent stuck in a loop")

API

detect_loop(events, *, window=4, repeat_threshold=3) -> LoopDetection

Scans events for a repeating window of length window. Returns the first window seen repeat_threshold times or more.

Each event is reduced to a signature via event.get("tool") or event.get("name") or event.get("type") (or str(event) for non-dicts).

should_stop(events, *, window=4, repeat_threshold=3) -> bool

Convenience wrapper returning the looping flag.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_loop_breaker_py-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_loop_breaker_py-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file agent_loop_breaker_py-0.1.0.tar.gz.

File metadata

  • Download URL: agent_loop_breaker_py-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for agent_loop_breaker_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7509be27c80d3fb517398c016e17b624299eaf37ffe7e3771cc6136b163b68e0
MD5 ba34d8f5c106d3688ceefc9089525661
BLAKE2b-256 cb2682ee91e22b21b65edb9edb6ba62cf427c71f867bf8e95db0faebf134c91c

See more details on using hashes here.

File details

Details for the file agent_loop_breaker_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_loop_breaker_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c00cfc1c50ef8dc293520ea8b3e9bef63c7ba36f51c1f5c8d984bd9d4e64d339
MD5 f635a217e27efb05fb396c5be22466d0
BLAKE2b-256 220f605dbaea47d810804087883f2764785b05e340d3326ca7816003bb60a392

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page