Agentic.CircuitBreaker
(agentic v0.2.2)
Copy Markdown
Per-tool circuit breaker for agent tool execution.
Tracks consecutive failures per tool name. After a configurable threshold (default 3), the tool is marked as "open" and calls are rejected instantly for a cooldown period (default 5 minutes).
State transitions: :closed (normal) -> 3 consecutive failures -> :open (rejecting) :open -> cooldown expires -> :half_open (testing) :half_open -> success -> :closed :half_open -> failure -> :open
Uses ETS for lock-free reads on the hot path. No GenServer needed.
Summary
Functions
Check if a tool is available (circuit closed or half-open).
Get the current state of a tool's circuit breaker.
Initialize the ETS table. Call once at app startup.
Record a failed tool execution. May trip the circuit.
Record a successful tool execution. Resets failure count.
Reset a specific tool's circuit breaker.
Reset all circuit breakers.
Types
Functions
@spec check(String.t()) :: :ok | {:error, :circuit_open}
Check if a tool is available (circuit closed or half-open).
Get the current state of a tool's circuit breaker.
Initialize the ETS table. Call once at app startup.
@spec record_failure(String.t()) :: :ok
Record a failed tool execution. May trip the circuit.
@spec record_success(String.t()) :: :ok
Record a successful tool execution. Resets failure count.
@spec reset(String.t()) :: :ok
Reset a specific tool's circuit breaker.
@spec reset_all() :: :ok
Reset all circuit breakers.