pub struct LoopGuard { /* private fields */ }Expand description
Circuit breaker that watches for repetitive tool call patterns and enforces a maximum iteration count.
Tracks call fingerprints, outcome fingerprints, and recent call history to detect various pathological patterns including ping-pong cycles.
Implementations§
Source§impl LoopGuard
impl LoopGuard
Sourcepub fn new(max_iterations: usize, _repetition_threshold: usize) -> Self
pub fn new(max_iterations: usize, _repetition_threshold: usize) -> Self
Create a new loop guard with default configuration.
Sourcepub fn with_config(config: GuardConfig) -> Self
pub fn with_config(config: GuardConfig) -> Self
Create a new loop guard with explicit configuration.
Sourcepub fn record_tool_calls(&mut self, tool_calls: &[ToolCall]) -> LoopGuardVerdict
pub fn record_tool_calls(&mut self, tool_calls: &[ToolCall]) -> LoopGuardVerdict
Record a set of tool calls and return a verdict.
This is the main entry point for the guard. Call this before executing each batch of tool calls from the LLM.
Sourcepub fn evaluate_call(&mut self, tool_call: &ToolCall) -> GuardVerdict
pub fn evaluate_call(&mut self, tool_call: &ToolCall) -> GuardVerdict
Evaluate a single tool call and return a graduated verdict.
Use this for finer-grained control where you want to handle Block vs CircuitBreak differently.
Sourcepub fn record_outcome(&mut self, tool_call: &ToolCall, result: &str)
pub fn record_outcome(&mut self, tool_call: &ToolCall, result: &str)
Record the outcome of a tool call (call hash + result hash).
If the same outcome has been seen before, it is auto-blocked for future iterations.
Sourcepub fn is_outcome_blocked(&self, tool_call: &ToolCall, result: &str) -> bool
pub fn is_outcome_blocked(&self, tool_call: &ToolCall, result: &str) -> bool
Check if an outcome would be blocked (same call + same result seen before).
Sourcepub fn record_iteration(&mut self) -> LoopGuardVerdict
pub fn record_iteration(&mut self) -> LoopGuardVerdict
Record a non-tool-call iteration (e.g. text-only response check).
Sourcepub fn iterations(&self) -> usize
pub fn iterations(&self) -> usize
Current iteration count.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LoopGuard
impl RefUnwindSafe for LoopGuard
impl Send for LoopGuard
impl Sync for LoopGuard
impl Unpin for LoopGuard
impl UnsafeUnpin for LoopGuard
impl UnwindSafe for LoopGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more