View as Markdown

Mandate · Guide

Set limits and policy

Use this guide to put one agent's spending under rules: who it may buy from, the amount a person must approve, a monthly budget with an end date, and a narrower grant for a sub-agent. You simulate the policy before it decides anything real.

Before you begin: the Mandate quickstart shows one rule end to end. Policies and grants explain the two objects this guide combines. Lists are available on every plan.

export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
LimitWhere it livesChecked when
Who the agent may buy fromA policy list and a ruleEvery decision
The amount a person approvesA policy ruleEvery decision
Per-order cap, budget and end dateA grantEvery decision under the grant
What a sub-agent may doA delegated grant, never wider than its parentEvery decision under the sub-grant

1. List the stores the agent may use

A policy list holds values a rule can test with in_list or not_in_list. Save the stores your agent buys from with PATCH /v1/account/policies/lists/{name}.

curl -s -X PATCH $PROVENANCE_API/v1/account/policies/lists/approved-suppliers \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "kind": "allow", "entries": ["brindlecote-office.example", "paper.example"] }'
{
  "object": "policy_list",
  "name": "approved-suppliers",
  "kind": "allow",
  "count": 2
}

2. Simulate the policy

Write the rules, then try them against facts with POST /v1/mandate/policies/simulate before anything depends on them. This document refuses a store that isn't on the list and sends anything over 250 to a person. Simulating decides nothing and records nothing.

curl -s -X POST $PROVENANCE_API/v1/mandate/policies/simulate \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": { "rules": [
      { "id": "known-suppliers-only", "when": [{ "fact": "counterparty", "op": "not_in_list", "value": "approved-suppliers" }], "require": { "deny": true }, "reason": "counterparty_not_approved" },
      { "id": "ask-above-250", "when": [{ "fact": "transaction_amount", "op": "gt", "value": 250 }], "require": { "approval": true } }
    ] },
    "facts": { "counterparty": "brindlecote-office.example", "transaction_amount": 400 }
  }'
{
  "object": "policy_simulation",
  "allowed": false,
  "reason": "approval_required",
  "requires_approval": true,
  "policy": {
    "id": "pol_3F9A1C7E52B04D8E6A1F27C9B4",
    "version": 0,
    "rule": {
      "id": "ask-above-250",
      "name": null,
      "phase": "assess",
      "action": "challenge",
      "conditions": [
        { "fact": "transaction_amount", "op": "gt", "value": 250, "actual": 400 }
      ]
    }
  }
}

Try the other cases the same way:

FactsResult
A listed store, 120allowed: true
A listed store, 400approval_required from ask-above-250
A store not on the list, any amountcounterparty_not_approved from known-suppliers-only

3. Activate the policy

Save the same document with PUT /v1/mandate/policies. It becomes the account's active version, and every decision from now on records which version decided it.

curl -s -X PUT $PROVENANCE_API/v1/mandate/policies \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "known suppliers, a person above 250",
    "document": { "rules": [
      { "id": "known-suppliers-only", "when": [{ "fact": "counterparty", "op": "not_in_list", "value": "approved-suppliers" }], "require": { "deny": true }, "reason": "counterparty_not_approved" },
      { "id": "ask-above-250", "when": [{ "fact": "transaction_amount", "op": "gt", "value": 250 }], "require": { "approval": true } }
    ] }
  }'
{
  "object": "policy_version",
  "domain": "intent",
  "active": true,
  "note": "known suppliers, a person above 250"
}

Your agent sends counterparty and transaction_amount in the context of each decision, as in the quickstart.

An action no rule decides is allowed. To ask a person about it instead, or refuse it, set the policy's fallback row: "fallback": { "assess": "review" } (or "reject") beside rules. The row always runs last and can't be deleted; the decision names it rul_default_fallback_assess. The rules embed shows it with its outcome as a choice.

The policy and an agent's grant are two layers: the grant's limits only narrow what the policy allows, and every decision checks both.

4. Give the agent a grant with a budget

A grant is standing permission: the agent acts within it without asking each time. Create one with POST /v1/mandate/grants: a cap per order, a monthly budget, the actions and stores it covers, and an end date.

curl -s -X POST $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "device_id": "dev_00000000000000000000000000000001",
    "agent_session_id": "sess_office_buyer",
    "purpose": "Keep the office stocked with paper and toner",
    "constraints": {
      "max_amount": 150,
      "budget_amount": 600,
      "budget_window": "month",
      "allowed_action_types": ["quote", "purchase"],
      "allowed_counterparties": ["brindlecote-office.example", "paper.example"],
      "expires_at": "2027-06-30T23:59:59Z"
    }
  }' | tee grant.json
{
  "object": "grant",
  "status": "active",
  "remaining_budget": 600,
  "purpose": "Keep the office stocked with paper and toner"
}

The agent sends mandate_token with each intent. A purchase over 150, past the month's budget, at another store or after the end date is refused under the grant; the policy's rules still apply on top.

export GRANT_ID=$(jq -r .id grant.json)

5. Narrow a sub-agent's grant

When the agent hands a task to a sub-agent, delegate a grant that can only be narrower: POST /v1/mandate/grants/{id}/delegate. This sub-agent only compares prices, with a smaller cap and budget. Stores and the end date are inherited when you leave them out.

curl -s -X POST $PROVENANCE_API/v1/mandate/grants/$GRANT_ID/delegate \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_session_id": "sess_price_checker",
    "purpose": "Compare toner prices at two stores",
    "purpose_tags": ["quote"],
    "constraints": { "max_amount": 40, "budget_amount": 60, "allowed_action_types": ["quote"] }
  }'
{
  "object": "grant",
  "status": "active",
  "depth": 1,
  "remaining_budget": 60,
  "purpose_tags": ["quote"]
}

chain lists the grants from the root to this one, so a store can see who delegated what. A delegation wider than its parent is refused; see delegate to sub-agents.

6. Put the sandbox account back

The sandbox account is shared. When you're done, return it to the default policy with DELETE /v1/mandate/policies.

curl -s -X DELETE $PROVENANCE_API/v1/mandate/policies \
  -H "Authorization: Bearer $PROVENANCE_KEY"
{
  "object": "policy",
  "is_default": true
}

Errors you might see

ErrorCauseFix
400 parameter_invalid on a grantA cap or budget of 0, or a sub-grant wider than its parentSend positive amounts no wider than the parent grant.
400 policy_invalidA rule names an unknown fact, operator or listSimulate first: it reports the same problem without saving.

See also