/** * Observer module for the observational memory system. * * Handles extracting observations from raw conversation messages via a * background LLM call. The observer watches the conversation and produces * structured, timestamped observations that become the agent's sole * memory of past interactions. * * References: * - observational-memory-architecture.md (Observer System section) * - compaction-strategy.md */ import type { CompleteFn } from '../compaction.js'; import type { AgentMessage } from '../../context-manager.js'; import type { ObserverOutput } from './types.js'; /** * Converts an array of AgentMessages into a formatted string for the * observer LLM. * * Each message is formatted with role and positional timestamp. Messages * with content arrays (tool calls/results) receive structured formatting * so the observer can extract meaningful takeaways. * * Messages with timestamps are formatted with their actual date and time. * Messages without timestamps fall back to sequential labels. * Messages are grouped by date when timestamps are available. */ export declare function formatMessagesForObserver(messages: AgentMessage[]): string; /** * Parse the raw LLM output from the observer. * * Extracts content from ``, ``, and * `` XML blocks. Uses simple string matching * (not a DOM parser) and is lenient with malformed output. * * If no `` tag is found, the entire output is used as * observations (graceful fallback). */ export declare function parseObserverOutput(raw: string): ObserverOutput; /** * Build the full observer system prompt. * * Starts with `OBSERVER_SYSTEM_PROMPT` from constants and optionally * appends consumer-provided custom instructions. * * @param previousObservations - Previous observations for context (unused in system prompt, kept for signature consistency) * @param previousObserverTokens - Token budget for previous observations (unused in system prompt) * @param customInstruction - Optional consumer-provided instruction to append * @returns The complete system prompt string */ export declare function buildObserverPrompt(previousObservations: string | null, previousObserverTokens: number, customInstruction?: string): string; /** * Build the message array to send to the observer LLM. * * Constructs a sequence of user messages: * 1. (Optional) Previous observations for deduplication context * 2. The formatted message history * 3. A task instruction to extract observations * * @param messages - The conversation messages to observe * @param previousObservations - Previous observations to prevent duplication * @param previousObserverTokens - Token budget for the previous observations context * @returns Array of message objects for the LLM call */ export declare function buildObserverMessages(messages: AgentMessage[], previousObservations: string | null, previousObserverTokens: number): unknown[]; /** * Check if the output contains degenerate repetition. * * Detects a line appearing 5+ times consecutively, which is a known * failure mode of LLMs under certain conditions (e.g., high temperature, * long context, repetitive input patterns). * * @param text - The text to check for repetition * @returns true if degenerate repetition is detected */ export declare function detectDegenerateRepetition(text: string): boolean; /** * Run the observer LLM call to extract observations from messages. * * Orchestrates the full observer pipeline: * 1. Builds the system prompt (with optional custom instructions) * 2. Builds the message array (with previous observations context) * 3. Calls the LLM via `complete` * 4. Parses the structured output * 5. Detects and retries on degenerate repetition (once) * * @param complete - The LLM completion function * @param messages - The conversation messages to observe * @param previousObservations - Previous observations for deduplication * @param config - Observer configuration * @returns Parsed observer output with observations, current task, and suggested response */ export declare function runObserver(complete: CompleteFn, messages: AgentMessage[], previousObservations: string | null, config: { previousObserverTokens: number; observerInstruction?: string; }): Promise; //# sourceMappingURL=observer.d.ts.map