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
finalizeVotes(votes, actionType, policy?)
Single-evaluator decision path. Takes votes and produces a final guard result.
- votes
GuardVote[]-- votes from evaluators - actionType
string-- the guard type (e.g."code_merge") - policy
GuardPolicy(optional) -- quorum and risk threshold overrides - Returns
GuardResult--{ decision, reason, risk_score, next_step }
computeDecision(votes, policy, mode?)
Multi-agent consensus path with weighted voting.
- votes
WeightedGuardVote[]-- votes with weight and reputation fields - policy
GuardPolicy--{ quorum, riskThreshold } - mode -- weighting mode:
"static"(raw weight),"reputation"(reputation/100),"hybrid"(weight * reputation/100). Defaults to"static". - Returns decision result with tally, quorum status, and combined risk
computeEffectiveWeight(weight, reputation, mode?)
Compute a single voter's effective weight based on the weighting mode.
tallyVotes(votes, mode?)
Tally an array of weighted votes into aggregate counts.
- Returns
{ yes, no, rewrite, totalWeight, weightedYes, weightedNo, weightedRewrite, voterCount }
reachesQuorum(tally, quorum)
Check if a tally meets the required quorum threshold.
createGuardEvaluatorRegistry()
Factory that returns a GuardEvaluatorRegistry pre-loaded with all 7 built-in guard types.
Examples
Custom evaluator registry
Register custom evaluators or override built-in ones:
Vote tallying
Related
- Schemas package -- types consumed by guards
- Consensus Policies -- policy algorithms that guards can use
- Security Model -- how guards fit into the security architecture