Class CircuitBreaker
Adaptive circuit breaker that wraps ToolLoopDetector to manage open/closed/half-open state transitions for tool invocations.
State machine:
Closed → (hard-stop detected) → Open → (cooldown expires) →
HalfOpen → (probe succeeds) → Closed.
public sealed class CircuitBreaker
- Inheritance
-
CircuitBreaker
- Inherited Members
Constructors
CircuitBreaker(ToolLoopDetector, TimeSpan?, int, bool)
public CircuitBreaker(ToolLoopDetector detector, TimeSpan? cooldownPeriod = null, int halfOpenProbeLimit = 2, bool hardenedMode = false)
Parameters
detectorToolLoopDetectorcooldownPeriodTimeSpan?halfOpenProbeLimitinthardenedModebool
Properties
CooldownPeriod
How long the circuit stays open before transitioning to half-open.
public TimeSpan CooldownPeriod { get; }
Property Value
Detector
The underlying loop detector.
public ToolLoopDetector Detector { get; }
Property Value
HalfOpenProbeLimit
Maximum calls allowed in half-open state to probe recovery.
public int HalfOpenProbeLimit { get; }
Property Value
HardenedMode
When true, the circuit breaker cannot be disabled even by user override.
public bool HardenedMode { get; }
Property Value
State
Current circuit state.
public CircuitState State { get; }
Property Value
TotalTrips
Total number of times the circuit has tripped since creation.
public int TotalTrips { get; }
Property Value
Methods
Evaluate(string, string?, string?, string?)
Evaluates whether the next tool call should proceed. Returns the decision and any loop detection diagnostics.
public CircuitBreakerResult Evaluate(string toolName, string? argsFingerprint = null, string? outputFingerprint = null, string? agentId = null)
Parameters
Returns
TryReset()
Manually resets the circuit breaker (only allowed if not in hardened mode).
public bool TryReset()