Agent Circuit Breaker Pattern
Prevent cascading failures and 'token burning' by halting agent execution when error thresholds are crossed.
Steps
- Define `failure_threshold` (e.g., 5 consecutive 5xx errors or 3 consecutive timeouts).
- Monitor `success_rate` across a sliding window of the last 50 tool calls.
- Trip circuit to 'OPEN' state immediately upon hitting the failure threshold.
- Implement a 'Cool-off Timer' (e.g., 60-120s) where all agent requests are auto-rejected.
- Transition to 'HALF-OPEN' after the timer expires to allow a single 'Probe Request'.
- Reset to 'CLOSED' only if the Probe Request returns a 200 OK / Valid JSON.