Trip the Loop: A Weekend Circuit Breaker for Agent Side Projects
Description and use
Implement a lightweight local circuit breaker to stop runaway agent loops by limiting turns, repeated calls, and consecutive errors.
Problem
Weekend agent loops can run indefinitely when a tool repeatedly fails or returns the same error, consuming turns and filling the terminal with identical errors.
Outcome
Implemented a lightweight, in-process circuit breaker that stops runaway agent loops after configurable thresholds, preventing resource exhaustion and improving reliability for weekend side projects.
Workflow
- 1. Define TripConfig with max_turns, identical_limit, error_limit, and open_cooldown_rejects.
- 2. Implement Tripwire dataclass to track state, turns, streaks, and last digest.
- 3. In the agent loop, call tripwire.precheck(tool_name, payload) before each tool invocation.
- 4. If precheck raises RuntimeError, handle the exception and terminate the loop gracefully.
- 5. On successful tool calls, update Tripwire counters and reset streaks as needed.
- 6. Use the state machine logic (closed, open, half_open) to decide whether to execute or reject calls.
- 7. Include unit tests that treat an opened circuit as a successful termination condition.
- 8. Deploy the single-file tripwire.py in the agent project without external dependencies.
Evidence
A small in-process circuit breaker — turn cap, identical-call tripwire, consecutive-error open state — is enough to stop that spiral without a platform rewrite.
Three trip conditions cover most of that weekend damage: Turn budget, Identical call, Error streak.
- Record date: 2026-09-22T05:30:19.083Z