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 -> loopStructs§
- Loop
Detector - Sliding-window loop detector.