UNPKG

claude-flow

Version:

Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration

88 lines 3.83 kB
/** * GAIA Voting — ADR-135 Track A * * Multi-attempt self-consistency voting wrapper around `runGaiaAgent`. * * Algorithm: * 1. Spawn N parallel `runGaiaAgent` calls, each with a distinct system-prompt * seed (web-first / code-first / cautious) and varied temperature (0.3/0.5/0.7). * 2. Collect all N final answers; filter out nulls. * 3. Normalize each answer: lowercase, trim, strip punctuation, normalize numbers. * 4. Count by normalized value; the highest-count non-null wins (majority vote). * 5. Tie-break: pick the attempt whose normalized answer won and has the lowest * error count (null/timed-out attempts score worst). * 6. All-disagree: pick the attempt with the lowest error/timeout count. * 7. All null: return null answer. * * Diversification system-prompt seeds (one per attempt, cycling if N > 3): * - "web-first" — prefer web_search before reasoning * - "code-first" — prefer code_exec/calculator before web * - "cautious" — step-by-step, verify each sub-claim before answering * * Temperature schedule (cycling if N > 3): * - attempt 0: 0.3 (conservative) * - attempt 1: 0.5 (balanced) * - attempt 2: 0.7 (exploratory) * * Expected L1 lift per ADR-135: +5-10pp. * Cost: N× per question (default N=3 → ~3× per question). * * Refs: ADR-135, ADR-133, #2156 */ import { type GaiaAgentResult } from './gaia-agent.js'; import type { GaiaQuestion } from './gaia-loader.js'; export interface VotingResult extends GaiaAgentResult { /** All individual attempt results (includes failed/null attempts). */ attempts: GaiaAgentResult[]; /** * How the winner was decided: * - 'majority' — at least 2 attempts agreed on the winning answer * - 'highest-confidence' — all attempts disagreed; winner had fewest errors/timeouts * - 'all-disagree-retry' — all non-null attempts gave different answers (same as highest-confidence) * - 'sole-survivor' — only one non-null attempt; used directly */ votingMethod: 'majority' | 'highest-confidence' | 'all-disagree-retry' | 'sole-survivor'; /** How many attempts produced the winning (normalized) answer. */ agreementCount: number; } export interface VotingOptions { /** Number of parallel attempts (default: 3). */ attempts?: number; /** * Optional custom system-prompt seed overrides per attempt (index-aligned). * Defaults to cycling through STRATEGY_SEEDS. */ diversityPromptSeeds?: string[]; /** * Number of attempts to run in parallel (default: attempts — full parallel). * Values < attempts cause sequential batches (useful for rate-limit avoidance). */ parallelism?: number; /** Model ID (default: 'claude-haiku-4-5'). */ model?: string; /** Max agent turns per attempt (default: 8). */ maxTurns?: number; /** Anthropic API key (resolved automatically if omitted). */ apiKey?: string; } /** * Normalize a raw answer string for voting comparison. * * Steps: * 1. Lowercase + trim. * 2. Collapse internal whitespace. * 3. Strip leading/trailing punctuation (commas, periods, quotes, etc.). * 4. Normalize numeric representations: "1,234" → "1234", "1.0" → "1", * "1.50" → "1.5". */ export declare function normalizeAnswer(raw: string): string; /** * Run a GAIA question N times in parallel with diversified strategies, * then majority-vote on the answer. * * @param question The GAIA question to answer. * @param options Voting + agent options. * @returns VotingResult containing the winning answer and all attempt traces. */ export declare function runGaiaAgentWithVoting(question: GaiaQuestion, options?: VotingOptions): Promise<VotingResult>; //# sourceMappingURL=gaia-voting.d.ts.map