Skip to Content
LaCrew docs
Protocol

IPolicyModule

The heart of the protocol. Modules stack on a node; first DENY wins; any ESCALATE routes upward.

interface IPolicyModule {
    function check(
        address agent,
        address target,
        uint256 value,
        bytes calldata data
    ) external view returns (Verdict);
    // Verdict: ALLOW | ESCALATE | DENY
}

Standard modules (reference contracts):

ModuleVerdict behavior
SpendCapPolicyESCALATE over per-agent / default cap, or over the per-epoch budget when one is set
WhitelistPolicyDENY non-whitelisted targets
RateLimitPolicyESCALATE when window count ≥ max (router calls record)
CumulativeValuePolicyESCALATE when settled value in the window would cross the budget (router calls recordValue)
TimeWindowPolicyDENY outside daily UTC window
CustomThird-party IPolicyModule implementations

PolicyStack composes modules: first DENY wins; any ESCALATE is sticky; else ALLOW.

Cumulative value budgets

SpendCapPolicy bounds one call, so ten calls just under the cap all pass. CumulativeValuePolicy(maxValue, maxValuePerTarget, windowSeconds) sums what actually settled instead: it escalates when the next spend would take the agent's value inside the window over maxValue, and, when maxValuePerTarget is non-zero, over that budget to a single payee. A spend that escalates and is then approved still counts, so an approved overage fills the window it landed in.

The router charges the module through IValueRecorder.recordValue(agent, target, value) on every settled spend with value — setValueRecorder for the org default, setNodeValueRecorder for a node with its own module. As with RateLimitPolicy, the recorder is bound once by the deployer (setRecorder), and both the global and the node's recorder are protected targets an agent cannot call through the router. The SDK's deployCumulativeValuePolicy deploys one with its recorder locked to the org's router; binding it takes setNodePolicy plus proposeSetNodeValueRecorder.

Windows are anchored at the first settled spend after the previous one lapsed. Value settled without escalation is at most maxValue within one window, and at most 2 × maxValue across any span of windowSeconds that straddles two windows.

Per-epoch budget on SpendCapPolicy

SpendCapPolicy can also budget per epoch, on the payroll cadence of EpochStreamer. setEpochSchedule(epochStart, epochSeconds, defaultBudget) turns it on (epochSeconds = 0 turns it off), and setAgentEpochBudget(agent, budget) overrides one agent. Both are admin- or governor-gated, like setAgentCap. A spend escalates when it is over the per-call cap or when it would take the agent's settled value in the current epoch over its budget.

Epochs are aligned to epochStart, not anchored at a spend, so up to twice the budget can settle across one epoch boundary. A new schedule starts a fresh epoch for every agent. The module is fed exactly like CumulativeValuePolicy: bind it as the router's value recorder (setValueRecorder or setNodeValueRecorder) and lock its recorder to the router (setRecorder, once). The router has one value recorder per node, so a node budgets either through SpendCapPolicy's epochs (per-agent budgets, governor-adjustable) or through CumulativeValuePolicy's anchored windows (immutable, with a per-payee budget), not both.

Lifetime value ceiling on a session key

Policies budget the agent. A session key can be bounded on its own: SessionRegistry.issueScopedTimedBudget(..., maxTotalValue) caps the value the key may propose over its whole life. The router charges every propose that proceeds, escalated or not, and reverts the one that would cross the ceiling with SessionTotalValueExceeded. A leaked key therefore cannot split a large spend into many calls under maxValue. remainingValue(agent, key) reads what is left. The orchestrator carries only that remainder onto a rotated key.

Per-node stacks

EscalationRouter keeps a default policy plus optional policyOf[node] overrides (setNodePolicy). Propose checks the agent's stack; resolve checks the approver's stack. DeployMockOrg wires a worker stack (whitelist + spend cap + rate limit) and a manager stack (whitelist + spend cap, no rate limit).

TODO

  • TODO: Spec module registry + upgrade path via GovernanceModule
  • TODO: Publish ABI + abitype package for off-chain preflight

On this page