/** * Confidence Filter — Multi-agent result confidence scoring & filtering * * Scores agent findings by confidence, filters by threshold, and optionally * validates low-confidence findings with a secondary agent. Inspired by * Claude Code's confidence-based multi-agent filtering pattern. * * @module ConfidenceFilter * @version 1.0.0 */ import type { AgentPayload, AgentContext } from '../types/agent-adapter'; import type { AdapterRegistry } from '../adapters/adapter-registry'; /** * A single finding produced by an agent, annotated with confidence. */ export interface Finding { /** Unique identifier for this finding */ id: string; /** Human-readable description of the finding */ description: string; /** Confidence score from 0 to 100 */ confidence: number; /** Agent that produced this finding */ sourceAgent: string; /** Agent that validated this finding (set after validation) */ validatedBy?: string; /** Whether validation passed (set after validation) */ validated?: boolean; /** Arbitrary metadata attached to the finding */ metadata?: Record; } /** * Result of filtering findings by confidence threshold. */ export interface FilterResult { /** Findings that passed the threshold */ accepted: Finding[]; /** Findings below the threshold */ rejected: Finding[]; /** Threshold that was applied */ threshold: number; } /** * Aggregation strategies for combining findings from multiple agents. */ export type AggregationStrategy = 'highest' | 'average' | 'unanimous' | 'majority'; /** * Result of aggregating multiple sets of findings. */ export interface AggregatedResult { /** Merged findings after applying aggregation strategy */ findings: Finding[]; /** Strategy that was used */ strategy: AggregationStrategy; /** Total number of input findings before aggregation */ totalInput: number; /** Number of sources that contributed */ sourceCount: number; } /** * Options for the ConfidenceFilter constructor. */ export interface ConfidenceFilterOptions { /** Default confidence threshold (0–100). Default: 70 */ defaultThreshold?: number; /** If true, findings below threshold are auto-validated with a second agent */ autoValidate?: boolean; /** Agent to use for validation passes */ validatorAgent?: string; /** Payload factory for validation calls */ validationPayloadFactory?: (finding: Finding) => AgentPayload; } /** * Filters and validates multi-agent findings based on confidence scores. * * @example * ```typescript * const filter = new ConfidenceFilter(registry, baseCtx, { defaultThreshold: 70 }); * * const findings: Finding[] = [ * { id: '1', description: 'SQL injection in login.ts', confidence: 95, sourceAgent: 'scanner-a' }, * { id: '2', description: 'Possible XSS in comments', confidence: 45, sourceAgent: 'scanner-b' }, * ]; * * const filtered = filter.filter(findings); * // filtered.accepted → finding #1, filtered.rejected → finding #2 * * // Validate a low-confidence finding with a secondary agent * const validated = await filter.validate(findings[1], 'expert-reviewer'); * ``` */ export declare class ConfidenceFilter { private registry; private baseContext; private options; /** * @param registry Adapter registry for validation calls (optional — filter-only mode if null) * @param baseContext Default execution context for validation agents * @param options Filter configuration */ constructor(registry: AdapterRegistry | null, baseContext: AgentContext | null, options?: ConfidenceFilterOptions); /** * Score a single finding. Returns a normalised 0–100 confidence score. * Currently a pass-through; override or extend for custom scoring logic. */ score(finding: Finding): number; /** * Filter findings by confidence threshold. * * @param findings Findings to filter * @param threshold Override the default threshold for this call */ filter(findings: Finding[], threshold?: number): FilterResult; /** * Validate a finding using a secondary agent. * The validator agent's result is used to update `validatedBy` and `validated`. * * @param finding The finding to validate * @param validatorAgentId Agent to perform the validation (overrides options) * @returns Updated finding with validation metadata */ validate(finding: Finding, validatorAgentId?: string): Promise; /** * Validate all rejected findings from a filter result. * Returns the updated filter result with re-scored findings. */ validateRejected(filterResult: FilterResult, validatorAgentId?: string): Promise; /** * Aggregate findings from multiple sources using a strategy. * * - `highest`: Keep the finding with the highest confidence for each id * - `average`: Average the confidence scores for each id * - `unanimous`: Only keep findings that appear in ALL sources * - `majority`: Only keep findings that appear in more than half of sources * * @param findingSets Arrays of findings from different agents * @param strategy Aggregation strategy to use */ aggregate(findingSets: Finding[][], strategy?: AggregationStrategy): AggregatedResult; } //# sourceMappingURL=confidence-filter.d.ts.map