@zanii/policy
v0.1.1
Published
Decide whether an agent action is allowed before it runs - amount caps, allow/deny lists, rate limits, and payload conditions that delegation scopes can't express.
Readme
@zanii/policy
Decide whether an agent action is allowed before it runs — on conditions a
delegation scope can't express: amount caps, allow/deny lists, time windows,
rate limits. It complements @zanii/runtime
(which enforces the tool manifest, delegation scope, and human-gate); this layer
reasons about the payload.
npm install @zanii/policyUsage
import { createPolicyEngine } from '@zanii/policy';
const engine = createPolicyEngine({
default: 'allow',
rules: [
{ id: 'sanctions', effect: 'deny', targets: ['pay.*'],
where: [{ field: 'to.country', op: 'in', value: ['IR', 'KP'] }] },
{ id: 'big-transfer', effect: 'require_approval', targets: ['pay.transfer'],
where: [{ field: 'amount', op: 'gt', value: 1000 }] },
{ id: 'email-flood', effect: 'deny', targets: ['email.send'],
rateLimit: { max: 100, perSeconds: 3600 } },
],
});
const { decision, rule, reason } = engine.evaluate({
target: 'pay.transfer',
payload: { amount: 5000, to: { country: 'US' } },
key: agentDid, // rate-limit bucket
});
// decision → 'require_approval'Ordered rules, first match wins, explicit default. Predicate ops:
eq ne lt lte gt gte in nin over dot-path payload fields. Target globs use the
same syntax as delegation scopes (pay.*, *).
Wire decision into your flow: deny → don't act, require_approval → route to
a human gate, allow → proceed and record the proof.
Changelog
- 0.1.0 — initial release:
createPolicyEngine, rules with predicates + fixed-window rate limits.
License
Apache-2.0.
