/** * RLM Context Manager * Implements token-saving techniques from the RLM paper (arXiv:2512.24601) * * Key techniques: * 1. Context condensation - Summarize intermediate results * 2. Sliding window - Keep recent turns in full, compress older ones * 3. Memory bank - Extract and store key findings * 4. Result compression - Compress sub-LLM results */ import type { Message } from './providers/types.js'; /** Memory bank entry for storing key findings */ export interface MemoryEntry { /** Unique identifier */ id: string; /** Type of finding */ type: 'file_analysis' | 'pattern' | 'dependency' | 'issue' | 'summary'; /** The key finding or insight */ content: string; /** Source file or context */ source?: string; /** Importance score (1-10) */ importance: number; /** Turn when this was discovered */ turn: number; } /** Compressed turn representation */ export interface CompressedTurn { /** Turn number */ turn: number; /** Brief summary of what was done */ summary: string; /** Key findings extracted */ findings: string[]; /** Whether code was executed */ hadCode: boolean; /** Whether there was an error */ hadError: boolean; } /** Context manager configuration */ export interface ContextManagerConfig { /** Number of recent turns to keep in full detail */ slidingWindowSize: number; /** Maximum memory bank entries */ maxMemoryEntries: number; /** Maximum characters for compressed turn summary */ maxSummaryLength: number; /** Maximum characters for sub-LLM result compression */ maxResultLength: number; /** Enable aggressive compression */ aggressiveCompression: boolean; } /** * Context Manager for RLM * Handles context compression and memory management */ export declare class ContextManager { private config; private memoryBank; private compressedHistory; constructor(config?: Partial); /** * Compress a sub-LLM result to save tokens * Extracts key information and truncates verbose output */ compressResult(result: string): string; /** * Extract key findings from a turn's execution result */ extractFindings(result: string, turn: number, source?: string): MemoryEntry[]; /** * Categorize a finding based on content */ private categorizeFinding; /** * Score a finding's importance (1-10) */ private scoreFinding; /** * Add findings to memory bank */ addToMemory(findings: MemoryEntry[]): void; /** * Compress a turn for history storage */ compressTurn(turn: number, response: string, executionResult: string | null, error: string | null): CompressedTurn; /** * Build optimized history for model context * Uses sliding window - recent turns in full, older turns compressed */ buildOptimizedHistory(fullHistory: Message[], _currentTurn: number): Message[]; /** * Build a summary of compressed history */ private buildCompressionSummary; /** * Register a completed turn for compression tracking */ registerTurn(turn: number, response: string, executionResult: string | null, error: string | null): void; /** * Get memory bank contents for final synthesis */ getMemoryBank(): MemoryEntry[]; /** * Get compressed history */ getCompressedHistory(): CompressedTurn[]; /** * Build a memory summary for the model */ buildMemorySummary(): string; /** * Reset the context manager */ reset(): void; /** * Get token savings estimate */ getTokenSavingsEstimate(): { originalChars: number; compressedChars: number; savings: number; }; } /** * Create a context manager with recommended settings */ export declare function createContextManager(options?: Partial): ContextManager; //# sourceMappingURL=context-manager.d.ts.map