Class ToolLoopDetector
Detects repetitive tool invocation patterns that indicate no-progress loops. Tracks a rolling window of recent calls and identifies:
- Same-tool/same-args repetitions (stuck loops).
- Ping-pong patterns between two tools/agents.
- High-frequency bursts of any single tool.
Thread-safe — designed to be shared across a session.
public sealed class ToolLoopDetector
- Inheritance
-
ToolLoopDetector
- Inherited Members
Constructors
ToolLoopDetector(int, int, int, int)
public ToolLoopDetector(int windowSize = 50, int repetitionWarningThreshold = 3, int repetitionHardStopThreshold = 5, int pingPongThreshold = 4)
Parameters
Properties
CurrentWindowCount
Returns the current invocation count in the window.
public int CurrentWindowCount { get; }
Property Value
PingPongThreshold
Number of alternating A→B→A→B calls that constitutes a ping-pong loop.
public int PingPongThreshold { get; }
Property Value
RepetitionHardStopThreshold
Number of identical (tool+args) calls in the window that triggers a hard stop.
public int RepetitionHardStopThreshold { get; }
Property Value
RepetitionWarningThreshold
Number of identical (tool+args) calls in the window that triggers a warning.
public int RepetitionWarningThreshold { get; }
Property Value
WindowSize
Maximum number of records kept in the rolling window.
public int WindowSize { get; }
Property Value
Methods
RecordAndEvaluate(string, string?, string?, string?)
Records a tool invocation and returns a detection result.
public LoopDetectionResult RecordAndEvaluate(string toolName, string? argsFingerprint = null, string? outputFingerprint = null, string? agentId = null)
Parameters
Returns
Reset()
Clears all recorded history (e.g. after a circuit breaker reset).
public void Reset()