/** * Reasoning Engine Module - LLM-based reasoning for pi-learn * * Supports hybrid scope: * - 'user' scope: Cross-project insights (traits, interests, goals) * - 'project' scope: Project-specific insights (code patterns, decisions) */ import type { Conclusion, ReasoningOutput, DreamOutput, Scope } from "../shared.js"; export interface ReasonedConclusion { content: string; type: "deductive" | "inductive" | "abductive"; premises: string[]; scope: Scope; confidence: number; embedding?: number[]; sourceSessionId: string; } export interface OnConclusionsCallback { (conclusions: ReasonedConclusion[], peerId: string, sessionFile: string): Promise; } export interface ReasoningEngineConfig { ollamaBaseUrl: string; ollamaApiKey: string; reasoningModel: string; embeddingModel: string; tokenBatchSize: number; retry?: Partial; concurrency?: number; onConclusions?: OnConclusionsCallback; } export interface RetryConfig { maxRetries: number; retryDelayMs: number; timeoutMs: number; maxBackoffMs: number; } export declare const DEFAULT_RETRY_CONFIG: RetryConfig; export declare function createReasoningEngine(config: ReasoningEngineConfig): ReasoningEngine; export interface ReasoningContext { globalConclusions?: Conclusion[]; localConclusions?: Conclusion[]; globalPeerCard?: { name?: string; occupation?: string; interests: string[]; traits: string[]; goals: string[]; }; } export declare class ReasoningEngine { private config; private messageQueue; private isProcessing; private maxRetries; private retryDelayMs; private timeoutMs; private maxBackoffMs; private concurrency; private activeRequests; private requestQueue; private lastProcessedAt; constructor(config: ReasoningEngineConfig); queue(item: { sessionFile: string; peerId: string; messages: Array<{ role: string; content: string; }>; queuedAt: number; }): void; getQueueSize(): number; isReasoning(): boolean; /** * Process unprocessed observations through reasoning and return conclusions. * Used by learn_reason_now to bridge the observation → conclusion gap. */ reasonOnObservations(observations: Array<{ id: string; content: string; role: string; sessionId: string; }>, peerId: string, existingContext?: ReasoningContext): Promise; generateEmbedding(text: string): Promise; /** * Reason about messages with optional context * @param messages Messages to reason about * @param _peerId Peer ID (unused, context determines scope) * @param context Optional context for informed reasoning */ reason(messages: Array<{ role: string; content: string; }>, _peerId: string, context?: ReasoningContext): Promise; /** * Dream - consolidate memories with scope classification * @param messages Recent messages * @param existingConclusions Existing conclusions (can be mixed scope) * @param context Optional context for informed dreaming */ dream(messages: Array<{ role: string; content: string; }>, existingConclusions: Conclusion[], context?: ReasoningContext): Promise; /** * Call Ollama chat endpoint with proper format for Ollama API */ private callOllamaChat; private processQueue; private callOllama; private sleep; /** * Calculate exponential backoff with jitter */ private calculateBackoff; /** * Classify error for better debugging */ private classifyError; /** * Acquire semaphore slot for concurrency control */ private acquireSemaphore; /** * Release semaphore slot */ private releaseSemaphore; /** * Build reasoning prompt with scope classification guidance */ private buildReasoningPrompt; /** * Parse reasoning output with scope classification */ private parseReasoningOutput; /** * Build dream prompt with scope classification */ private buildDreamPrompt; /** * Parse dream output with scope classification */ private parseDreamOutput; } //# sourceMappingURL=reasoning.d.ts.map