Skip to main content
Every tool call is automatically protected by a circuit breaker that stops repeated failures from wasting time.
Sync and Async Parity: Circuit breaker protection now applies uniformly to both sync and async tool execution paths. Previously, async calls bypassed circuit breaker checks.
This tool-level circuit breaker is separate from the new LLM idle-timeout circuit breaker, which protects against LLM provider stalls during model calls.
Per-agent scoping: breakers are now keyed per agent instance (tool_{id(self)}_{function_name}), so two agents that expose same-named tools (e.g. search) no longer share one breaker — one agent’s failures can’t degrade the other. Per-agent breakers are auto-pruned from the registry when the Agent is garbage-collected (via weakref.finalize), so a reused instance id can’t inherit a stale OPEN breaker — agent.close() / aclose() merely reclaims that space earlier.
The user triggers a flaky tool; repeated failures open the breaker so later calls fail fast instead of looping on errors.

Quick Start

1

Works by default

Circuit breaker protection is automatically enabled for every tool call with zero configuration needed.
2

Detect open circuit

When a tool fails 5 times consecutively, subsequent calls return an error dictionary instead of calling the tool.
3

Tune or reset

Customize circuit breaker behavior or reset all breakers between test runs.

How It Works


Configuration Options


What Does NOT Trip the Breaker

Circuit breakers ignore certain error types to avoid false positives:
  • Approval denied errors - User permission issues don’t indicate tool problems
  • Permission denied errors - Access control failures aren’t tool failures
  • Approval process errors - User workflow issues shouldn’t trigger circuit breaking
These errors are handled normally by the agent without affecting circuit breaker state.

Lifecycle

Per-agent breakers are pruned from the global registry automatically when the Agent is garbage-collected — a weakref.finalize callback is registered when each breaker is created. This closes the CPython id()-reuse window without requiring agent.close() / agent.aclose() to be called explicitly. Calling agent.close() / agent.aclose() still triggers the same cleanup earlier and deterministically — recommended when you know the agent is done and want registry space reclaimed immediately.

Common Patterns

Monitor circuit breaker health and statistics for debugging.

Best Practices

Circuit breakers prevent cascading failures and protect system stability. Keep them enabled in production environments to ensure reliable agent operation.
Track circuit breaker statistics in your monitoring systems. Frequent openings indicate underlying tool reliability issues that need attention.
Per-agent breakers are auto-pruned when the Agent is collected (via weakref.finalize). Explicit agent.close() reclaims registry space immediately. reset_all_circuit_breakers() remains the sledgehammer for global tests that need a clean slate regardless of GC timing.
When handling circuit_open: true responses, provide clear user feedback about temporary tool unavailability and suggest retry timeframes or alternative approaches.

Model Failover

Automatic LLM provider switching

Error Handling

Comprehensive error handling strategies