/** * Self-reflection (Python parity: `Agent(reflection=...)`, `ReflectionConfig`, * and the reflection loop in `agent/chat_mixin.py`). * * After the model answers, it is asked to critique its own response and to * say whether the answer is satisfactory. An unsatisfactory answer is * regenerated using the critique, up to `maxIterations` times; a * satisfactory verdict only counts once `minIterations` reflections have run. * * The loop is written against a `complete(messages, schema?)` callback so it * can be tested without a provider and so the Agent decides which transport * (OpenAI-compatible service or AI SDK backend) performs the calls. */ /** Resolved reflection settings (Python `ReflectionConfig`). */ export interface ReflectionConfig { /** Reflections that must run before a "yes" is accepted (Python `min_iterations`, default 1). */ minIterations: number; /** Upper bound on reflection rounds (Python `max_iterations`, default 3). */ maxIterations: number; /** Model used for the critique, when different from the agent's (Python `llm`). */ llm?: string; /** Custom critique instruction (Python `prompt`). */ prompt?: string; } /** Python `REFLECTION_PRESETS`. */ export declare const REFLECTION_PRESETS: Readonly>>; /** Python's default critique instruction. */ export declare const DEFAULT_REFLECTION_INSTRUCTION = "Identify any flaws, improvements, or actions."; /** Python: "Now regenerate your response using the reflection you made". */ export declare const REGENERATE_PROMPT = "Now regenerate your response using the reflection you made"; /** Structured-output schema for the critique (Python `ReflectionOutput`). */ export declare const REFLECTION_OUTPUT_SCHEMA: Record; /** * Turn the constructor option into a config. `true` uses Python's defaults, * a string names a preset, an object supplies fields (snake_case accepted). * Unknown presets throw, as Python's resolver does. */ export declare function resolveReflection(input: boolean | string | Record | undefined | null): ReflectionConfig | undefined; /** Python's reflection prompt, verbatim in structure. */ export declare function buildReflectionPrompt(response: string, instruction?: string): string; export interface ReflectionOutput { reflection: string; satisfactory: 'yes' | 'no'; } /** * Parse the critique. Accepts a bare JSON object or one wrapped in a code * fence (Python `clean_json_output`). Throws when no verdict can be read. */ export declare function parseReflectionOutput(text: string): ReflectionOutput; /** A conversation message as the loop manipulates it. */ export interface ReflectionMessage { role: string; content: string | null; [key: string]: unknown; } export interface ReflectionRound { reflection: string; satisfactory: 'yes' | 'no'; /** The response the critique was about. */ response: string; } export interface RunReflectionLoopOptions { /** The model's first answer. */ response: string; /** The conversation so far (system + history + prompt). Mutated: the critique exchange is appended. */ messages: ReflectionMessage[]; config: ReflectionConfig; /** * Ask the model for a completion of `messages`. When `schema` is given the * call is for the structured critique; the Agent may honour it with * response_format or ignore it and rely on the prompt. */ complete: (messages: ReflectionMessage[], schema?: Record) => Promise; /** Observer for each critique (Python's `display_self_reflection`). */ onReflection?: (round: ReflectionRound) => void; } /** * Run Python's reflection loop and return the accepted response together * with every critique that was made. */ export declare function runReflectionLoop(opts: RunReflectionLoopOptions): Promise<{ response: string; rounds: ReflectionRound[]; }>;