loopcircuit
Autonomous agent loop governor, circuit-breaker, and anti-thrashing engine for AI agents and LLM execution pipelines.
Zero hard dependencies. Framework-agnostic. Runs in sub-millisecond execution time.
The Problem in 2026
Frontier AI agents (Claude Code, Cursor, AutoGen, CrewAI, or custom while loops) frequently suffer from runaway execution traps:
- Exact Repetition: Invoking the exact same broken tool with identical arguments 20 times in a row.
- Ping-Pong Oscillation: Flip-flopping between two tools (e.g.
edit_file➔run_test➔revert➔edit_file) without making forward progress. - Error Vortices: Trapped repeatedly hitting the same underlying exception.
- Budget Blowouts: Burning through $50+ in LLM API credits overnight while unsupervised.
loopcircuit provides a deterministic safety net and circuit breaker that halts runaway loops and dynamically injects surgical interventions to snap agents back on track.
Key Capabilities
- Cycle & Oscillation Detection: Identifies periodic cycles of length 1 (repetition), length 2 (ping-pong), and length 3+ (wandering) via canonical argument hashing.
- Error Vortex Recognition: Normalizes stack traces (stripping memory addresses, line numbers, and timestamps) to detect recurring root causes.
- Multi-Policy Actions:
raise: Immediately trips and raises structured exceptions (ThrashDetectedError,BudgetExceededError,MaxStepsExceededError).intervene: Injects a structured system intervention prompt directly into the agent's context to mandate a strategy change.warn: Half-opens the circuit, logging telemetry while allowing execution to proceed with probation.
- Financial & Token Caps: Hard limits on dollar costs and cumulative token consumption.
- Drop-in
@governedDecorator & Context Manager: Works seamlessly across sync and async loops.
Installation
pip install loopcircuit
Quickstart
As an Interactive Circuit Breaker
from loopcircuit import CircuitBreaker
# Configure safety thresholds
breaker = CircuitBreaker(
max_steps=20,
max_cost_usd=2.00,
repetition_threshold=3,
on_trip="intervene" # Injects corrective prompt instead of crashing
)
for step in agent_execution:
# Record each tool invocation
intervention = breaker.record(
tool_name=step.tool,
arguments=step.args,
result=step.output,
cost_usd=step.cost
)
if intervention.is_warning:
# Feed the generated pattern-breaking prompt back to the LLM
step.inject_system_prompt(intervention.recovery_prompt)
As a Decorator
from loopcircuit import governed
@governed(max_steps=15, max_cost_usd=1.00, on_trip="raise")
def run_agent_loop(task: str, breaker=None):
while True:
action = planner(task)
result = execute(action)
breaker.record(action.tool, action.args, result=result)
CLI Trace Auditor
Replay and audit agent trace logs (.jsonl) to detect loops and calculate spend:
loopcircuit audit agent_run.jsonl
loopcircuit audit agent_run.jsonl --max-cost 2.50 --json
License
MIT License.
Metadata
Release files for loopcircuit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| loopcircuit-0.1.0.tar.gz | 16.8 kB | Without provenance | Details for loopcircuit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| loopcircuit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for loopcircuit-0.1.0-py3-none-any.whl |
Total release size: 33.2 kB
Release files / loopcircuit-0.1.0.tar.gz
| Download URL | loopcircuit-0.1.0.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec7335c152ac235b8028af3b31e383f9a1360cab8db9ca3e9789f3c9b074a2b1
|
|
BLAKE2b-256 checksum How to use checksums |
b47dd56718aa9f7678653149584cc3af67ec0dda024829cc5883876708c56c46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / loopcircuit-0.1.0-py3-none-any.whl
| Download URL | loopcircuit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23e83e39dd4b696c54ced550b60b9d8bb8ae3622d1bef4089bd6f6d98a527413
|
|
BLAKE2b-256 checksum How to use checksums |
9b4465c680b8090bc6dec8ace4f155f321e902b8909f812731b69939936dbec9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for loopcircuit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.