Skip to main content

Crate tool_loop_break

Crate tool_loop_break 

Source
Expand description

§tool-loop-break

Detect repeated agent tool invocations and signal “loop” before the agent burns the budget.

Approach: maintain a sliding window of the last window recorded (tool_name, args_fingerprint) tuples. When any tuple has appeared >= threshold times inside the window, [record] returns true.

args_fingerprint is whatever you decide — typically a short hash of the JSON arguments — so identical arg sets collide.

§Example

use tool_loop_break::LoopDetector;
let mut d = LoopDetector::new(10, 3); // window=10, threshold=3
assert!(!d.record("read_file", "abc"));
assert!(!d.record("read_file", "abc"));
assert!(d.record("read_file", "abc")); // third within window -> loop

Structs§

LoopDetector
Sliding-window loop detector.