Wrapper
Wrap any async function with a consensus gate using multiple reviewers and configurable strategies.
Overview
@consensus-tools/wrapper wraps any async function with a consensus gate. Multiple reviewers score the function's output, and a configurable strategy (unanimous, majority, or threshold) decides whether to allow, block, retry, or escalate.
Installation
Quick start
API reference
consensus()
Wraps a function with a consensus gate. Returns an async function with the same signature that produces a DecisionResult.
Options:
| Field | Type | Description |
|---|---|---|
name | string | Identifier for this consensus gate |
fn | (...args: A) => Promise<T> | The function to wrap |
reviewers | ReviewerFn<T>[] | Array of reviewer functions |
strategy | StrategyConfig | Strategy and threshold |
maxRetries | number | Max retry attempts before escalation |
hooks | LifecycleHooks<T> | Optional lifecycle hooks |
aggregateScores()
Use the aggregation logic directly without the full wrapper.
ReviewerFn<T>
A reviewer receives the function output and context, returning a score between 0 and 1.
ReviewResult fields:
| Field | Type | Description |
|---|---|---|
score | number | 0-1 score |
rationale | string | Explanation |
block | boolean | If true, immediately blocks regardless of strategy |
Strategies
| Strategy | Passes when... |
|---|---|
"threshold" | Average score >= threshold (default 0.5) |
"majority" | More than half of reviewers score >= threshold |
"unanimous" | Every reviewer scores >= threshold |
Hard blocks
Setting block: true on any reviewer's result immediately blocks the operation regardless of strategy or scores.