Expand description
Cross-turn tool-call loop guard — ported from omp
packages/ai/src/utils/tool-call-loop-guard.ts.
MIT — attribution: adapted from omp (Can Berk Güder, earendil-works).
§Purpose
Models occasionally fixate on a single tool call: the same name and arguments across consecutive turns, with the same (often unhelpful) result. Left unchecked the loop burns the context window and the user’s quota indefinitely.
ToolCallLoopGuard records each completed assistant turn and fires
when the same single-tool call (modulo argument key ordering) hits
a configurable threshold. Multi-call turns reset detection.
Exempt tools (e.g. read for progressive file exploration, ls for
directory walks) bypass detection — their repetition is legitimate.
Structs§
- Repeated
Tool Call Detection - Details surfaced when a loop is recognised. Hosts can render these into a steering message or abort the agent run.
- Tool
Call Loop Guard - Detects consecutive identical assistant tool calls across model turns.
- Tool
Call Loop Guard Options - Runtime settings for cross-turn tool-call repetition detection.
- Tool
Call Loop Turn - One completed assistant turn for the guard to evaluate.
- Tool
Call Ref - A tool call as seen by the guard. Hosts adapt their provider-native types into this shape.
- Tool
Result Ref - A tool result as seen by the guard.