Case Study: Circuit Breaker
Case Study: Circuit Breaker
A 4-step formula ran into a file permission error. The agent could not read its prompt from a temp directory. Instead of looping forever, three runtime protections fired in sequence.
The run
What happened
The agent asked for permission to read a temp file. Was denied. Asked again. Was denied again. On the third attempt, the runtime intervened. Three protections fired:
1. Spin detection
The runtime measures token output velocity across iterations. When the agent produced fewer than 500 tokens for two consecutive iterations after three total, the engine recognized a cognitive loop -- the agent was repeating the same request/denial cycle.
It triggered graceful completion, not a hard kill. The agent got a clean shutdown signal.
2. Cost cap
The step closed at 3 turns and $0.10. Without velocity monitoring, the agent would have continued for up to 50 turns, burning through rate limits and accumulating cost on repeated permission requests that could never succeed.
3. DAG circuit breaker
The first step completed without its expected keyword (LOOP_COMPLETE). The engine marked it as failed. The remaining three steps depended on it. The circuit breaker recognized the entire DAG was compromised and halted the sequence. Downstream steps never ran on broken state.
Without these protections
A standard shell script piping to an LLM would:
- Loop until context limit (50+ turns)
- Burn API cost on repeated identical requests
- Execute downstream steps on empty/broken output
- Produce no useful signal about what went wrong
Key takeaways
- Velocity monitoring catches agents stuck in loops. The engine measures output rate, not just volume.
- Graceful completion preserves agent state. The step closes cleanly, not with a SIGKILL.
- DAG awareness prevents cascading damage. Failed steps propagate through dependency edges.
- CIR crystallization records what happened. The 3 patterns become evidence for future runs.
See also
- Workflow Patterns for recipe composition
- Local Inference & Shell for backend selection
- Architecture for the local-first execution model