gepa-spo
Version:
Genetic-Pareto prompt optimizer to evolve system prompts from a few rollouts with modular support and intelligent crossover
32 lines (31 loc) • 1.61 kB
TypeScript
import type { LLM, Module } from './types.js';
export interface JudgedExample {
user: string;
output: string;
feedback: string;
/** Optional execution trace summary */
execTrace?: string;
/** Optional evaluator trace summary */
evalTrace?: string;
}
/**
* Summarizes trace data into a bounded, deterministic string format
* @param traces - Raw trace data from execution or evaluation
* @param maxSize - Maximum size in characters for the summary
* @returns Summarized trace string or undefined if no traces
*/
export declare function summarizeTraces(traces: Record<string, unknown> | null | undefined, maxSize?: number): string | undefined;
/** Build the meta-prompt that asks the LLM to rewrite the system prompt */
export declare function buildReflectionPrompt(system: string, examples: JudgedExample[], strategyHint?: string): string;
/** Build the meta-prompt that asks the LLM to rewrite a specific module */
export declare function buildModuleReflectionPrompt(module: Module, allModules: Module[], moduleIndex: number, examples: JudgedExample[], strategyHint?: string): string;
/** Ask the LLM to propose an improved system prompt */
export declare function proposeNewSystem(llm: LLM, system: string, examples: JudgedExample[], strategyHint?: string): Promise<string>;
/** Ask the LLM to propose an improved module prompt */
export declare function proposeNewModule(llm: LLM, candidate: {
system?: string;
modules?: Module[];
}, moduleIndex: number, examples: JudgedExample[], strategyHint?: string): Promise<{
system?: string;
modules?: Module[];
}>;