Guards
Deterministic guard evaluation engine with weighted voting and multi-agent consensus decisions.
Overview
@consensus-tools/guards is the deterministic guard evaluation engine for consensus-tools. It evaluates agent actions against 7 built-in guard types, tallies weighted votes across multiple evaluators, and computes ALLOW / BLOCK / REWRITE / REQUIRE_HUMAN decisions.
Installation
Peer dependency
This package requires @consensus-tools/schemas as a peer dependency.
Quick start
Run the built-in evaluators against an action and finalize a decision:
API reference
evaluatorVotes(input)
Built-in deterministic evaluator for all 7 guard types.
- input
GuardEvaluateInput-- the action and context to evaluate - Returns
GuardVote[]-- array of votes from built-in evaluators
computeDecision(votes, policy, mode?)
Multi-agent weighted voting with quorum and risk threshold:
Weighting modes: "static" (raw weight), "reputation" (reputation/100), "hybrid" (weight × reputation/100).
Vote tallying utilities
Evaluator registry
Register custom evaluators or override built-in ones:
Guard templates
Create custom guard domains with the template system. Templates integrate with both the evaluator registry and the @consensus-tools/wrapper package:
Simpler entry point
For the simplest integration path, use @consensus-tools/universal which composes guards + wrapper with sensible defaults.
Exports reference
| Export | Kind | Description |
|---|---|---|
evaluatorVotes | Function | Built-in deterministic evaluator for all 7 guard types |
computeEffectiveWeight | Function | (weight, reputation, mode?) => number |
tallyVotes | Function | (votes, mode?) => VoteTally |
reachesQuorum | Function | (tally, quorum) => boolean |
finalizeVotes | Function | (votes, actionType, policy?) => GuardResult (single-evaluator path) |
computeDecision | Function | (votes, policy, mode?) => { decision, tally, quorumMet, ... } (multi-agent path) |
normalizeGuardType | Function | (type) => GuardType -- falls back to "agent_action" |
GuardEvaluatorRegistry | Class | Registry of evaluator functions keyed by guard type |
createGuardEvaluatorRegistry | Function | Factory that returns a pre-loaded registry |
createGuardTemplate | Function | Create a custom guard domain with registry + wrapper integration |
EvaluatorFn | Type | (input: GuardEvaluateInput) => GuardVote[] |