UNPKG

claude-flow-novice

Version:

Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture Includes Local RuVector Accelerator and all CFN skills for complete functionality.

142 lines (141 loc) 5.23 kB
/** * Confidence Score System - Validation and tracking for agent confidence scores * Migrated from legacy/v1/src/coordination/confidence-score-system.ts */ import { Logger } from '../core/logger.js'; /** * System for validating and tracking confidence scores in CFN Loop */ export class ConfidenceScoreSystem { logger; memoryManager; constructor(memoryManager){ this.memoryManager = memoryManager; const loggerConfig = process.env.CLAUDE_FLOW_ENV === 'test' ? { level: 'error', format: 'json', destination: 'console' } : { level: 'info', format: 'json', destination: 'console' }; this.logger = new Logger(loggerConfig, { component: 'ConfidenceScoreSystem' }); } /** * Validate confidence scores against threshold gate */ validateConfidenceGate(scores, options) { const { threshold, requireUnanimous = false } = options; if (scores.length === 0) { this.logger.warn('No confidence scores provided for validation'); return { passed: false, overallConfidence: 0, lowConfidenceAgents: [], threshold, totalAgents: 0, unanimous: false }; } // Calculate overall confidence (average) const totalConfidence = scores.reduce((sum, score)=>sum + score.confidence, 0); const overallConfidence = totalConfidence / scores.length; // Find low confidence agents const lowConfidenceAgents = scores.filter((score)=>score.confidence < threshold).map((score)=>({ agentId: score.agentId, confidence: score.confidence, reasoning: score.reasoning, blockers: score.blockers })); // Check if unanimous (all agents above threshold) const unanimous = lowConfidenceAgents.length === 0; // Determine if gate passes let passed = false; if (requireUnanimous) { passed = unanimous; } else { passed = overallConfidence >= threshold; } const result = { passed, overallConfidence, lowConfidenceAgents, threshold, totalAgents: scores.length, unanimous }; this.logger.info('Confidence gate validation complete', { passed, overallConfidence, threshold, totalAgents: scores.length, lowConfidenceCount: lowConfidenceAgents.length, unanimous, requireUnanimous }); return result; } /** * Collect confidence score from agent response */ collectScore(agentResponse) { const score = { agentId: agentResponse.agentId, agentType: agentResponse.agentType, confidence: agentResponse.confidence ?? 0.5, reasoning: agentResponse.reasoning, blockers: agentResponse.blockers, timestamp: Date.now() }; this.logger.debug('Collected confidence score', { agentId: score.agentId, confidence: score.confidence }); return score; } /** * Aggregate multiple confidence scores */ aggregateScores(scores) { if (scores.length === 0) { return { average: 0, min: 0, max: 0, median: 0, totalAgents: 0 }; } const confidenceValues = scores.map((s)=>s.confidence).sort((a, b)=>a - b); const sum = confidenceValues.reduce((acc, val)=>acc + val, 0); return { average: sum / scores.length, min: confidenceValues[0], max: confidenceValues[confidenceValues.length - 1], median: confidenceValues[Math.floor(confidenceValues.length / 2)], totalAgents: scores.length }; } /** * Get formatted confidence report */ getConfidenceReport(validation) { const status = validation.passed ? '✓ PASSED' : '✗ FAILED'; const lines = [ `Confidence Gate: ${status}`, `Overall Confidence: ${(validation.overallConfidence * 100).toFixed(1)}%`, `Threshold: ${(validation.threshold * 100).toFixed(1)}%`, `Total Agents: ${validation.totalAgents}`, `Unanimous: ${validation.unanimous ? 'Yes' : 'No'}` ]; if (validation.lowConfidenceAgents.length > 0) { lines.push(''); lines.push('Low Confidence Agents:'); for (const agent of validation.lowConfidenceAgents){ lines.push(` - ${agent.agentId}: ${(agent.confidence * 100).toFixed(1)}%${agent.reasoning ? ` (${agent.reasoning})` : ''}`); if (agent.blockers && agent.blockers.length > 0) { lines.push(` Blockers: ${agent.blockers.join(', ')}`); } } } return lines.join('\n'); } } //# sourceMappingURL=confidence-score-system.js.map