/** * Context Management Data Models for PraisonAI TypeScript SDK. * * Python parity with praisonaiagents/context/models.py: * - ContextSegment enum * - ContextLedger class * - BudgetAllocation class * - ContextSnapshot class * - OptimizerStrategy enum * - OptimizationResult class * - MonitorConfig class * - ContextConfig class */ import { type CompactionStrategyType, type ContextCompactionPolicyProtocol } from './policy'; /** * Segments that contribute to context. * Python parity with ContextSegment enum. */ export declare const ContextSegment: { readonly SYSTEM_PROMPT: "system_prompt"; readonly RULES: "rules"; readonly SKILLS: "skills"; readonly MEMORY: "memory"; readonly TOOLS_SCHEMA: "tools_schema"; readonly HISTORY: "history"; readonly TOOL_OUTPUTS: "tool_outputs"; readonly BUFFER: "buffer"; }; export type ContextSegmentType = typeof ContextSegment[keyof typeof ContextSegment]; /** * Context optimization strategies. * Python parity with OptimizerStrategy enum. */ export declare const OptimizerStrategy: { readonly TRUNCATE: "truncate"; readonly SLIDING_WINDOW: "sliding_window"; readonly SUMMARIZE: "summarize"; readonly PRUNE_TOOLS: "prune_tools"; readonly NON_DESTRUCTIVE: "non_destructive"; readonly SMART: "smart"; }; export type OptimizerStrategyType = typeof OptimizerStrategy[keyof typeof OptimizerStrategy]; /** * Tracks token usage across context segments. * Python parity with ContextLedger dataclass. */ export interface ContextLedger { systemPrompt: number; rules: number; skills: number; memory: number; toolsSchema: number; history: number; toolOutputs: number; buffer: number; turnCount: number; messageCount: number; toolCallCount: number; } /** * Create a new ContextLedger with defaults. */ export declare function createContextLedger(partial?: Partial): ContextLedger; /** * Get total tokens from ledger. */ export declare function getLedgerTotal(ledger: ContextLedger): number; /** * Token budget allocation across segments. * Python parity with BudgetAllocation dataclass. */ export interface BudgetAllocation { modelLimit: number; outputReserve: number; systemPrompt: number; rules: number; skills: number; memory: number; toolsSchema: number; history: number; toolOutputs: number; buffer: number; } /** * Create a new BudgetAllocation with defaults. */ export declare function createBudgetAllocation(partial?: Partial): BudgetAllocation; /** * Get usable tokens after output reserve. */ export declare function getUsableBudget(budget: BudgetAllocation): number; /** * Get computed history budget. */ export declare function getHistoryBudget(budget: BudgetAllocation): number; /** * Configuration for context monitoring. * Python parity with MonitorConfig dataclass. */ export interface MonitorConfig { enabled: boolean; path: string; format: 'human' | 'json'; frequency: 'turn' | 'tool_call' | 'manual' | 'overflow'; redactSensitive: boolean; multiAgentFiles: boolean; } /** * Create a new MonitorConfig with defaults. */ export declare function createMonitorConfig(partial?: Partial): MonitorConfig; /** * Complete context management configuration. * Python parity with ContextConfig dataclass. */ export interface ContextConfig { autoCompact: boolean; compactThreshold: number; strategy: OptimizerStrategyType; outputReserve: number; historyRatio: number; toolOutputMax: number; defaultToolOutputMax: number; pruneAfterTokens: number; protectedTools: string[]; toolLimits: Record; monitor: MonitorConfig; keepRecentTurns: number; llmSummarize: boolean; smartToolSummarize: boolean; sessionTracking: boolean; trackSummary: boolean; trackGoal: boolean; trackPlan: boolean; trackProgress: boolean; aggregateMemory: boolean; aggregateSources: string[]; aggregateMaxTokens: number; compressionMinGainPct: number; compressionMaxAttempts: number; toolBudgets: Record; toolSummarizeLimits: Record; estimationMode: string; logEstimationMismatch: boolean; mismatchThresholdPct: number; monitorEnabled: boolean; monitorPath: string; monitorFormat: string; monitorFrequency: string; monitorWriteMode: string; redactSensitive: boolean; snapshotTiming: string; allowAbsolutePaths: boolean; source: string; } /** * Create a new ContextConfig with defaults. */ export declare function createContextConfig(partial?: Partial): ContextConfig; /** * Map a CompactionStrategy (context/policy.ts, Python context/protocols.py) * onto the OptimizerStrategy used by ContextConfig / ManagerConfig. * * - truncate -> truncate * - summarise -> summarize * - drop_oldest_tools -> prune_tools * - sliding_window -> sliding_window */ export declare function compactionStrategyToOptimizerStrategy(strategy: CompactionStrategyType | string): OptimizerStrategyType; /** * Derive the compaction fields of a ContextConfig from a compaction policy. * * Returns a new config (the input is not mutated) whose `compactThreshold` * is the policy's `triggerAt`, `keepRecentTurns` its `preserveLastNTurns`, * `compressionMaxAttempts` its `maxCompactionAttempts`, and `strategy` the * mapped {@link compactionStrategyToOptimizerStrategy}. `autoCompact` is * switched on because a policy exists to be acted upon. * * Python keeps these as separate objects (ContextConfig vs * ContextCompactionPolicyAdapter); this helper is the TypeScript bridge that * lets the policy drive `compactThreshold`. */ export declare function applyCompactionPolicy(config: ContextConfig, policy: ContextCompactionPolicyProtocol): ContextConfig; /** * Create a recipe-optimized ContextConfig. * Python parity with ContextConfig.for_recipe(). */ export declare function createRecipeContextConfig(): ContextConfig; /** * Result of context optimization. * Python parity with OptimizationResult dataclass. */ export interface OptimizationResult { originalTokens: number; optimizedTokens: number; tokensSaved: number; strategyUsed: OptimizerStrategyType; messagesRemoved: number; messagesTagged: number; toolOutputsPruned: number; toolOutputsSummarized: number; tokensSavedBySummarization: number; tokensSavedByTruncation: number; summaryAdded: boolean; } /** * Create a new OptimizationResult with defaults. */ export declare function createOptimizationResult(partial?: Partial): OptimizationResult; /** * Get reduction percentage from optimization result. */ export declare function getReductionPercent(result: OptimizationResult): number; /** * A snapshot of the current context state. * Python parity with ContextSnapshot dataclass. */ export interface ContextSnapshot { timestamp: string; sessionId: string; agentName: string; modelName: string; budget: BudgetAllocation | null; ledger: ContextLedger | null; utilization: number; systemPromptContent: string; rulesContent: string; skillsContent: string; memoryContent: string; toolsSchemaContent: string; historyContent: Array>; warnings: string[]; } /** * Create a new ContextSnapshot with defaults. */ export declare function createContextSnapshot(partial?: Partial): ContextSnapshot; /** * Configuration for ContextManager. * Python parity with ManagerConfig dataclass. */ export interface ManagerConfig { modelLimit: number; outputReserve: number; defaultToolOutputMax: number; compactThreshold: number; strategy: OptimizerStrategyType; compressionMinGainPct: number; compressionMaxAttempts: number; toolBudgets: Record; toolSummarizeLimits: Record; estimationMode: string; logEstimationMismatch: boolean; mismatchThresholdPct: number; monitorEnabled: boolean; monitorPath: string; monitorFormat: string; monitorFrequency: string; monitorWriteMode: string; redactSensitive: boolean; snapshotTiming: string; allowAbsolutePaths: boolean; } /** * Create a new ManagerConfig with defaults. */ export declare function createManagerConfig(partial?: Partial): ManagerConfig;