The Circuit Breaker Pattern
Basic Usage
Circuit States
| State | Behavior |
|---|---|
| CLOSED | Normal operation. Calls allowed. Failures counted. |
| OPEN | All calls blocked. Waiting for timeout. |
| HALF_OPEN | Limited calls allowed. Testing if service recovered. |
Circuit Breaker Registry
Manage multiple circuit breakers:Global Stop (Emergency)
Stop everything immediately:Per-Agent Breakers
Different agents can have different breakers:Monitoring Circuits
Handling Circuit Open
Integration with Workflow
Best Practices
Use circuit breakers for all external APIs
Use circuit breakers for all external APIs
Not just LLM providers - any external service can fail.
Set appropriate timeouts
Set appropriate timeouts
Too short = circuit never recovers. Too long = downtime persists.
30-60 seconds is a good starting point.
Monitor circuit states
Monitor circuit states
If circuits are opening frequently, investigate the root cause.
Have fallback strategies
Have fallback strategies
What happens when a circuit opens? Have a plan.