/** * Tool Error Tracker - Tracks tool failures per session/turn * * Prevents agent from getting stuck in tool failure loops by: * - Counting failures per tool * - Tracking total failures * - Providing retry hints to agent */ export interface ToolFailureRecord { toolName: string; failureCount: number; lastError?: string; lastErrorTime: number; } export interface ToolErrorTrackerConfig { maxFailuresPerTool: number; maxTotalFailures: number; resetOnTurnEnd: boolean; failureWindowMs: number; } export declare class ToolErrorTracker { private failures; private totalFailures; private config; constructor(config?: Partial); /** * Record a tool failure */ recordFailure(toolName: string, error?: string): void; /** * Get failure count for a specific tool */ getFailureCount(toolName: string): number; /** * Get remaining attempts for a tool */ remainingAttempts(toolName: string): number; /** * Check if a specific tool has reached its failure limit */ isToolLimitReached(toolName: string): boolean; /** * Check if total failure limit is reached */ isTotalLimitReached(): boolean; /** * Check if any limit is reached (tool-specific or total) */ isAnyLimitReached(): boolean; /** * Get the tool that has reached its limit (if any) */ getLimitReachedTool(): string | null; /** * Get failure hint message for agent */ getFailureHint(toolName: string): string; /** * Get all failure records */ getFailures(): Map; /** * Get summary of failures */ getSummary(): { total: number; byTool: Record; }; /** * Reset all counters (called at end of turn) */ reset(): void; /** * Reset failures for a specific tool */ resetTool(toolName: string): void; /** * Get tracker configuration */ getConfig(): ToolErrorTrackerConfig; /** * Clean up old failures (outside the failure window) */ cleanupOldFailures(): void; }