/** * SpeculativeExecutor — Dispatch the same task to multiple agents in parallel, * then pick the best result via confidence scoring. * * Uses FanOutFanIn for parallel dispatch and ConfidenceFilter for quality-based * winner selection. Optimistic concurrency: spend the extra budget up-front * and discard inferior results. * * @module SpeculativeExecutor */ /** A candidate agent for speculative execution */ export interface SpeculativeCandidate { agentId: string; /** Optional label for logging/tracing */ label?: string; /** Per-candidate timeout override (ms) */ timeoutMs?: number; } /** Scored result from a speculative candidate */ export interface SpeculativeResult { agentId: string; label?: string; success: boolean; data: unknown; confidence: number; durationMs: number; } /** Final outcome of speculative execution */ export interface SpeculativeOutcome { /** The winning result (highest confidence above threshold) */ winner: SpeculativeResult | null; /** All candidate results, sorted by confidence descending */ candidates: SpeculativeResult[]; /** Whether a winner was selected */ hasWinner: boolean; /** Total wall-clock time for the speculative run */ totalMs: number; /** How many candidates succeeded */ successCount: number; } /** Configuration for speculative execution */ export interface SpeculativeOptions { /** Minimum confidence to be considered a valid winner (0-100, default 50) */ minConfidence?: number; /** Global timeout for all candidates (ms, default 30000) */ timeoutMs?: number; /** Maximum concurrent candidates (default: all) */ concurrency?: number; } /** Executor function: (agentId, payload) → { success, data, confidence } */ export type SpeculativeExecutorFn = (agentId: string, payload: Record) => Promise<{ success: boolean; data: unknown; confidence: number; }>; /** * Dispatch one task to multiple agents, pick the best result. * * @example * ```ts * const executor = new SpeculativeExecutor(async (agentId, payload) => { * const result = await adapters.executeAgent(agentId, payload, ctx); * return { * success: result.success, * data: result.data, * confidence: result.data?.confidence ?? 70, * }; * }); * * const outcome = await executor.race( * { instruction: 'Summarize this document', context: { doc: '...' } }, * [{ agentId: 'gpt4' }, { agentId: 'claude' }, { agentId: 'gemini' }], * ); * if (outcome.hasWinner) { * console.log(`Winner: ${outcome.winner!.agentId} (${outcome.winner!.confidence})`); * } * ``` */ export declare class SpeculativeExecutor { private executeFn; constructor(executeFn: SpeculativeExecutorFn); /** * Race the same payload across multiple candidate agents. * Returns the highest-confidence successful result. */ race(payload: Record, candidates: SpeculativeCandidate[], options?: SpeculativeOptions): Promise; private executeWithTimeout; } //# sourceMappingURL=speculative-executor.d.ts.map