Universal
Drop-in governance facade for any AI agent. Add multi-persona deliberation in 3 lines of code.
Overview
@consensus-tools/universal adds a governance layer to any AI agent in one line. Two operating modes:
- Regex mode (default): Three rule-based reviewers (security, compliance, user-impact) evaluate tool output using pattern matching — no LLM calls, no network requests, sub-millisecond overhead.
- LLM Persona mode (when
config.modelis provided): Multiple AI personas deliberate on each tool call before execution, with reputation-weighted voting, automatic persona respawn, and risk-tier classification.
Installation
Optional peer dependencies (install only what you need):
Quick start
Regex mode — any tool executor
Objects with .execute, .invoke, or .call methods are also accepted.
LLM Persona mode — multi-model deliberation
Provide a model adapter to activate LLM Persona Mode:
Shadow mode — runs governance but never blocks. Useful for evaluating before enforcing:
API reference
consensus.wrap(wrappable, config?)
| Parameter | Type | Description |
|---|---|---|
wrappable | Wrappable | Function, or object with .execute / .invoke / .call |
config | Partial<UniversalConfig> | Optional configuration |
Returns a ToolExecutor — (toolName: string, args: Record<string, unknown>) => Promise<unknown>.
In LLM mode, the returned executor also has .feedback(signal) for sending human feedback to the reputation system.
Framework adapters
Configuration
| Option | Default | Description |
|---|---|---|
policy | "majority" | Aggregation strategy. Supports "majority", "supermajority", "unanimous", "threshold:X", and all 9 core policy types. |
guards | ["agent_action"] | Guard domain names to use as reviewers |
failPolicy | "closed" | "closed" throws ConsensusBlockedError on block. "open" allows through (dev/test only). |
storage | "memory" | "memory" or an IStorage instance for persisting decisions |
logger | true | true, false, or a custom (event) => void handler |
onDecision | — | Called after every deliberation |
onError | — | Called on unexpected errors |
model | — | Activates LLM mode. Provider-agnostic (messages) => Promise<string> |
pack | "default" | Persona pack: "default" (3 personas) or "governance" (5 personas) |
personas | — | Custom persona array (overrides pack) |
mode | "enforce" | "enforce" blocks on rejection. "shadow" logs but never blocks. |
riskTiers | — | Per-tool risk tier overrides: { "my_tool": "low" | "high" } |
personaTimeout | 3000 | Per-persona LLM timeout in ms |
respawnThreshold | 0.15 | Trigger respawn below this reputation score |
reputationStore | — | IStorage instance for persisting reputation across restarts |
onFeedback | — | Called after .feedback() updates reputation |
Risk tier classification (LLM mode)
Tools are auto-classified by name. High-risk tools get full LLM deliberation; low-risk tools fast-path through regex only.
| Tier | Pattern examples | Default |
|---|---|---|
| High | send, delete, write, deploy, merge, grant, execute, transfer | Falls back to high |
| Low | get, list, search, read, check, verify, view, describe |
Override with riskTiers: { "my_tool": "low" }.
Error types
| Error | When thrown |
|---|---|
ConsensusBlockedError | Deliberation blocked and failPolicy is "closed" |
MissingDependencyError | Optional peer dep not installed (langchain / ai-sdk / mcp) |
ConfigError | Invalid policy name |
Exports reference
| Export | Kind | Description |
|---|---|---|
consensus | Object | Main facade with .wrap(), .langchain(), .aiSdk(), .mcp() |
ConsensusBlockedError | Class | Thrown when deliberation blocks |
MissingDependencyError | Class | Thrown when an optional peer dep is missing |
ConfigError | Class | Thrown for invalid configuration |
ReputationManager | Class | Per-persona reputation tracking (LLM mode) |
classifyTool | Function | Classify a tool name into a risk tier |
deliberate | Function | LLM persona deliberation engine |
Wrappable | Type | ToolExecutor | { execute } | { invoke } | { call } |
ToolExecutor | Type | (toolName: string, args: Record<string, unknown>) => Promise<unknown> |
UniversalConfig | Type | Full configuration interface |
ModelAdapter | Type | (messages: ModelMessage[]) => Promise<string> |
LlmDecisionResult | Type | Decision result from LLM persona deliberation |
FeedbackSignal | Type | Human feedback signal for reputation updates |