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.