pub struct LoopDetector { /* private fields */ }Expand description
Detects repeated action patterns in agent loops.
Usage:
ⓘ
let mut detector = LoopDetector::new(6); // abort after 6 repeats
for action in actions {
let sig = format!("tool:{}:{}", action.name, action.key_arg);
match detector.check(&sig) {
LoopStatus::Ok => { /* proceed */ }
LoopStatus::Warning(n) => { /* inject warning into context */ }
LoopStatus::Abort(n) => { /* stop the loop */ }
}
}Implementations§
Source§impl LoopDetector
impl LoopDetector
Sourcepub fn new(abort_threshold: usize) -> Self
pub fn new(abort_threshold: usize) -> Self
Create detector. Warns at abort_threshold / 2, aborts at abort_threshold.
Sourcepub fn with_thresholds(warn_threshold: usize, abort_threshold: usize) -> Self
pub fn with_thresholds(warn_threshold: usize, abort_threshold: usize) -> Self
Create detector with explicit warn threshold.
Sourcepub fn check(&mut self, signature: &str) -> LoopStatus
pub fn check(&mut self, signature: &str) -> LoopStatus
Check a combined signature for the current step’s actions.
signature should uniquely identify the action(s) being taken.
If multiple actions, join their signatures with |.
pub fn repeat_count(&self) -> usize
Auto Trait Implementations§
impl Freeze for LoopDetector
impl RefUnwindSafe for LoopDetector
impl Send for LoopDetector
impl Sync for LoopDetector
impl Unpin for LoopDetector
impl UnsafeUnpin for LoopDetector
impl UnwindSafe for LoopDetector
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
Mutably borrows from an owned value. Read more