/** * Leaper Agent - Context Engine * * Abstract base class for context management strategies, plus a * ConversationContext wrapper that delegates compression to an engine. * Translated from Python agent/context_engine.py. */ import type { ChatMessage } from '../types.js'; export interface ContextEngineStatus { lastPromptTokens: number; thresholdTokens: number; contextLength: number; usagePercent: number; compressionCount: number; } export declare abstract class ContextEngine { abstract readonly name: string; lastPromptTokens: number; lastCompletionTokens: number; lastTotalTokens: number; thresholdTokens: number; contextLength: number; compressionCount: number; thresholdPercent: number; protectFirstN: number; protectLastN: number; abstract updateFromResponse(usage: { prompt_tokens: number; completion_tokens: number; total_tokens: number; }): void; abstract shouldCompress(promptTokens?: number): boolean; abstract compress(messages: ChatMessage[], currentTokens?: number, focusTopic?: string): ChatMessage[]; /** Called before sending messages to the LLM to check preflight compression need. */ shouldCompressPreflight(_messages: ChatMessage[]): boolean; /** Returns false when the middle slice is too small to bother compressing. */ hasContentToCompress(_messages: ChatMessage[]): boolean; onSessionStart(_sessionId: string, _kwargs?: Record): void; onSessionEnd(_sessionId: string, _messages: ChatMessage[]): void; onSessionReset(): void; /** Return OpenAI-style tool schemas the engine exposes to the agent loop. */ getToolSchemas(): unknown[]; /** Dispatch a tool call routed to this engine. */ handleToolCall(name: string, _args: Record): string; getStatus(): ContextEngineStatus; /** Called when the active model changes so threshold can be recalculated. */ updateModel(_model: string, contextLength: number): void; } /** * Conversation context tracker. * * Maintains the running message history and delegates compression decisions * and execution to an optional ContextEngine. The engine is intentionally * optional so the class can be used as a plain message accumulator without * any compression strategy. */ export declare class ConversationContext { private messages; private engine; constructor(engine?: ContextEngine); /** Append a single message to the history. */ addMessage(msg: ChatMessage): void; /** Return a shallow copy of the current message list. */ getContext(): ChatMessage[]; /** * Rough token estimate using the chars/4 heuristic. * Defaults to the stored message list when no argument is provided. */ estimateTokens(messages?: ChatMessage[]): number; /** Ask the engine whether the current history warrants compression. */ shouldCompress(): boolean; /** Run the engine's compress() in-place on the stored messages. */ compress(focusTopic?: string): void; /** Discard the entire history. */ clear(): void; } //# sourceMappingURL=engine.d.ts.map