Table of Contents

Class CircuitBreaker

Namespace
JD.AI.Core.Safety
Assembly
JD.AI.Core.dll

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

detector ToolLoopDetector
cooldownPeriod TimeSpan?
halfOpenProbeLimit int
hardenedMode bool

Properties

CooldownPeriod

How long the circuit stays open before transitioning to half-open.

public TimeSpan CooldownPeriod { get; }

Property Value

TimeSpan

Detector

The underlying loop detector.

public ToolLoopDetector Detector { get; }

Property Value

ToolLoopDetector

HalfOpenProbeLimit

Maximum calls allowed in half-open state to probe recovery.

public int HalfOpenProbeLimit { get; }

Property Value

int

HardenedMode

When true, the circuit breaker cannot be disabled even by user override.

public bool HardenedMode { get; }

Property Value

bool

State

Current circuit state.

public CircuitState State { get; }

Property Value

CircuitState

TotalTrips

Total number of times the circuit has tripped since creation.

public int TotalTrips { get; }

Property Value

int

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

toolName string
argsFingerprint string
outputFingerprint string
agentId string

Returns

CircuitBreakerResult

TryReset()

Manually resets the circuit breaker (only allowed if not in hardened mode).

public bool TryReset()

Returns

bool