/** * Tool Chain Tracker - Tracks tool call chains and execution flow * * Based on Agent Harness theory: "Every production-grade Agent converges * on this core loop: while(model returns tool calls): execute tool → * capture result → append to context" */ export interface ToolCallNode { id: string; toolName: string; params: Record; result?: unknown; error?: string; durationMs: number; timestamp: number; children: ToolCallNode[]; metadata?: Record; } export interface ToolChain { sessionKey: string; startTime: number; endTime?: number; nodes: ToolCallNode[]; totalCalls: number; successfulCalls: number; failedCalls: number; totalDurationMs: number; } export interface ToolChainTrackerConfig { enabled: boolean; maxChainsPerSession: number; maxNodesPerChain: number; trackParams: boolean; trackResults: boolean; autoPrune: boolean; } export declare class ToolChainTracker { private chains; private currentChainId; private config; constructor(config?: Partial); /** * Start a new tool chain for a session */ startChain(sessionKey: string): string; /** * Record a tool call in the chain */ recordCall(sessionKey: string, toolName: string, params: Record, durationMs?: number): string; /** * Record tool call result */ recordResult(sessionKey: string, nodeId: string, result?: unknown, error?: string, durationMs?: number): void; /** * End the current chain for a session */ endChain(sessionKey: string): void; /** * Get chain summary as text */ getChainSummary(sessionKey: string): string; /** * Get chain visualization (ASCII tree) */ getChainVisualization(sessionKey: string): string; /** * Get all chains for a session */ getSessionChains(sessionKey: string): ToolChain[]; /** * Get current active chain */ getCurrentChain(sessionKey: string): ToolChain | undefined; /** * Get chain statistics */ getStats(): { totalChains: number; activeChains: number; totalToolCalls: number; avgSuccessRate: number; }; /** * Export chains as JSON */ exportChains(sessionKey?: string): string; /** * Reset all chains */ reset(): void; /** * Get config */ getConfig(): ToolChainTrackerConfig; /** * Update config */ setConfig(config: Partial): void; private generateChainId; private generateNodeId; private calculateSuccessRate; private pruneChain; private pruneOldChains; }