/** * Loop Guard — Detects repetitive tool call patterns within an agent turn * and produces context injections for the LLM. * * Design: pure function that analyzes recent tool call history (already in * the transcript) and returns: * - A developer-role message to inject into the next LLM request * - A set of tool names to temporarily hide from the model * * This operates at the orchestration layer (before LLM sees tools/messages) * rather than the execution layer, so the model naturally stops calling * blocked tools without receiving confusing "fake" tool outputs. */ export interface RecentToolCall { name: string; params: unknown; /** Optional: tool result text (for same-result detection). */ resultPreview?: string; } export interface LoopGuardConfig { /** Consecutive identical calls before injecting a soft warning (default: 2). */ softThreshold: number; /** Consecutive identical calls before hiding the tool (default: 3). */ hideThreshold: number; } export interface LoopGuardResult { /** Developer message to inject into LLM context (null = no loop). */ injection: string | null; /** Tool names to remove from the available tools list. */ hiddenTools: Set; } /** * Analyze recent tool calls and produce loop guard result. * * Pure function — no side effects, no shared state. */ export declare function detectToolLoops(recentCalls: readonly RecentToolCall[], config?: Partial): LoopGuardResult;