# Class ConsensusEngine

Consensus engine for multi-agent decision making.

#### Example

    const engine = new ConsensusEngine({ defaultTimeout: 30000 });
    const proposalResult = await engine.propose({
      title: 'Use microservices architecture',
      description: 'Proposal to adopt microservices',
      algorithm: 'supermajority',
    });
    if (proposalResult.ok) {
      await engine.vote(proposalResult.value, 'agent-1', {
        decision: 'approve',
        confidence: 0.9,
        reasoning: 'Good for scalability',
      });
    }

#### Implements

- IConsensusEngine

- Defined in packages/nexus-agents/src/consensus/engine.ts:127

##### Index

### Constructors

constructor

### Methods

setVoterExpansionCallback
propose
vote
getResult
close
getMetrics
updateAgentPerformance
getAgentPerformance
getActiveProposalCount
getCacheSize
clearCache

## Constructors

### constructor

- new ConsensusEngine(
  config?: Partial<ConsensusEngineConfig>,
  logger?: ILogger,
  ): ConsensusEngine

  #### Parameters

  - `Optional` config: Partial<ConsensusEngineConfig>
  - `Optional` logger: ILogger

  #### Returns ConsensusEngine

  - Defined in packages/nexus-agents/src/consensus/engine.ts:140

## Methods

### setVoterExpansionCallback

- setVoterExpansionCallback(callback: VoterExpansionCallback): void

  Sets the callback for incremental quorum voter expansion (Issue #1408). When ambiguous votes are detected, this callback requests additional voters.

  #### Parameters

  - callback: VoterExpansionCallback

  #### Returns void

  - Defined in packages/nexus-agents/src/consensus/engine.ts:153

### propose

- propose(
  proposal: {
  id?: string;
  title: string;
  description: string;
  algorithm:
  | "simple_majority"
  | "supermajority"
  | "unanimous"
  | "proof_of_learning"
  | "opinion_wise"
  | "higher_order";
  timeout?: number;
  requiredVoters?: string[];
  metadata?: Record<string, unknown>;
  createdAt?: string;
  },
  ): Promise<Result<string, ConsensusError>>

  #### Parameters

  - proposal: {
    id?: string;
    title: string;
    description: string;
    algorithm:
    | "simple_majority"
    | "supermajority"
    | "unanimous"
    | "proof_of_learning"
    | "opinion_wise"
    | "higher_order";
    timeout?: number;
    requiredVoters?: string[];
    metadata?: Record<string, unknown>;
    createdAt?: string;
    }

  #### Returns Promise<Result<string, ConsensusError>>

  Implementation of IConsensusEngine.propose

  - Defined in packages/nexus-agents/src/consensus/engine.ts:157

### vote

- vote(
  proposalId: string,
  agentId: string,
  vote: {
  decision: "approve" | "reject" | "abstain";
  reasoning: string;
  confidence: number;
  conditions?: string[];
  rejectionCategories?: (
  | "YAGNI"
  | "DRY_VIOLATION"
  | "OVER_ENGINEERING"
  | "SCOPE_CREEP"
  | "SECURITY_RISK"
  | "MISALIGNED"
  | "INSUFFICIENT_EVIDENCE"
  )[];
  findings?: {
  summary: string;
  location: string;
  severity: "low"
  | "medium"
  | "high"
  | "critical";
  gate: {
  reread_cited_line: "failed" | "skipped" | "passed";
  traced_call_path: "failed" | "skipped" | "passed";
  named_assertion: string;
  ruled_out_language_non_issue: "failed" | "skipped" | "passed";
  };
  claim: string;
  }[];
  timestamp?: string;
  },
  ): Promise<Result<void, ConsensusError>>

  #### Parameters

  - proposalId: string
  - agentId: string
  - vote: {
    decision: "approve" | "reject" | "abstain";
    reasoning: string;
    confidence: number;
    conditions?: string[];
    rejectionCategories?: (
    | "YAGNI"
    | "DRY_VIOLATION"
    | "OVER_ENGINEERING"
    | "SCOPE_CREEP"
    | "SECURITY_RISK"
    | "MISALIGNED"
    | "INSUFFICIENT_EVIDENCE"
    )[];
    findings?: {
    summary: string;
    location: string;
    severity: "low"
    | "medium"
    | "high"
    | "critical";
    gate: {
    reread_cited_line: "failed" | "skipped" | "passed";
    traced_call_path: "failed" | "skipped" | "passed";
    named_assertion: string;
    ruled_out_language_non_issue: "failed" | "skipped" | "passed";
    };
    claim: string;
    }[];
    timestamp?: string;
    }

    - ##### decision: "approve" | "reject" | "abstain"

    - ##### reasoning: string

    - ##### confidence: number

    - ##### `Optional` conditions?: string[]

    - ##### `Optional` rejectionCategories?: (
      | "YAGNI"
      | "DRY_VIOLATION"
      | "OVER_ENGINEERING"
      | "SCOPE_CREEP"
      | "SECURITY_RISK"
      | "MISALIGNED"
      | "INSUFFICIENT_EVIDENCE"
      )[]

      Structured rejection categories for reject→refine→re-vote loops (Issue #1213).

    - ##### `Optional` findings?: {
      summary: string;
      location: string;
      severity: "low" | "medium" | "high" | "critical";
      gate: {
      reread_cited_line: "failed" | "skipped" | "passed";
      traced_call_path: "failed" | "skipped" | "passed";
      named_assertion: string;
      ruled_out_language_non_issue: "failed" | "skipped" | "passed";
      };
      claim: string;
      }[]

      Pre-verified PR-review findings (#2245 v4 follow-up). Optional; populated only when the voter emits the structured top-level array.

    - ##### `Optional` timestamp?: string

  #### Returns Promise<Result<void, ConsensusError>>

  Implementation of IConsensusEngine.vote

  - Defined in packages/nexus-agents/src/consensus/engine.ts:198

### getResult

- getResult(proposalId: string): Promise<Result<ConsensusResult, ConsensusError>>

  #### Parameters

  - proposalId: string

  #### Returns Promise<Result<ConsensusResult, ConsensusError>>

  Implementation of IConsensusEngine.getResult

  - Defined in packages/nexus-agents/src/consensus/engine.ts:233

### close

- close(proposalId: string): Promise<Result<ConsensusResult, ConsensusError>>

  #### Parameters

  - proposalId: string

  #### Returns Promise<Result<ConsensusResult, ConsensusError>>

  Implementation of IConsensusEngine.close

  - Defined in packages/nexus-agents/src/consensus/engine.ts:246

### getMetrics

- getMetrics(): ConsensusMetrics

  #### Returns ConsensusMetrics

  Implementation of IConsensusEngine.getMetrics

  - Defined in packages/nexus-agents/src/consensus/engine.ts:250

### updateAgentPerformance

- updateAgentPerformance(agentId: string, wasCorrect: boolean): void

  #### Parameters

  - agentId: string
  - wasCorrect: boolean

  #### Returns void

  - Defined in packages/nexus-agents/src/consensus/engine.ts:266

### getAgentPerformance

- getAgentPerformance(agentId: string): AgentPerformance | undefined

  #### Parameters

  - agentId: string

  #### Returns AgentPerformance | undefined

  - Defined in packages/nexus-agents/src/consensus/engine.ts:291

### getActiveProposalCount

- getActiveProposalCount(): number

  #### Returns number

  - Defined in packages/nexus-agents/src/consensus/engine.ts:295

### getCacheSize

- getCacheSize(): number

  Gets the current cache size (for testing/monitoring).

  #### Returns number

  - Defined in packages/nexus-agents/src/consensus/engine.ts:655

### clearCache

- clearCache(): void

  Clears the proposal content cache (for testing/reset).

  #### Returns void

  - Defined in packages/nexus-agents/src/consensus/engine.ts:662