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
| Limit | Where it lives | Checked when |
|---|---|---|
| Who the agent may buy from | A policy list and a rule | Every decision |
| The amount a person approves | A policy rule | Every decision |
| Per-order cap, budget and end date | A grant | Every decision under the grant |
| What a sub-agent may do | A delegated grant, never wider than its parent | Every 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 /.
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"] }'
import { Provenance } from "@provenanceauth/sdk";
const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
await fetch(`${process.env.PROVENANCE_API}/v1/account/policies/lists/approved-suppliers`, {
method: "PATCH",
headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ kind: "allow", entries: ["brindlecote-office.example", "paper.example"] }),
});
import os, httpx
from provenanceauth import Provenance
prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
httpx.patch(f"{os.environ['PROVENANCE_API']}/v1/account/policies/lists/approved-suppliers",
headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
json={"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 / 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 }
}'
const rules = {
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 } },
],
};
const sim = await prov.mandate.policies.simulate({ document: rules, facts: { counterparty: "brindlecote-office.example", transaction_amount: 400 } });
rules = {"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}},
]}
sim = prov.mandate.policies.simulate(document=rules, 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:
| Facts | Result |
|---|---|
| A listed store, 120 | allowed: true |
| A listed store, 400 | approval_ from ask-above-250 |
| A store not on the list, any amount | counterparty_ from known-suppliers-only |
3. Activate the policy
Save the same document with PUT /. 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 } }
] }
}'
await prov.mandate.policies.set(rules, { note: "known suppliers, a person above 250" });
prov.mandate.policies.set(rules, note="known suppliers, a person above 250")
{
"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 /: 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
const grant = await prov.mandate.grants.create({
deviceId: "dev_00000000000000000000000000000001",
agentSessionId: "sess_office_buyer",
purpose: "Keep the office stocked with paper and toner",
constraints: {
maxAmount: 150,
budgetAmount: 600,
budgetWindow: "month",
allowedActionTypes: ["quote", "purchase"],
allowedCounterparties: ["brindlecote-office.example", "paper.example"],
expiresAt: "2027-06-30T23:59:59Z",
},
});
grant = prov.mandate.grants.create(
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",
},
)
{
"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 /. 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"] }
}'
const sub = await prov.mandate.grants.delegate(grant.id, {
agentSessionId: "sess_price_checker",
purpose: "Compare toner prices at two stores",
purposeTags: ["quote"],
constraints: { maxAmount: 40, budgetAmount: 60, allowedActionTypes: ["quote"] },
});
sub = prov.mandate.grants.delegate(
grant["id"],
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 /.
curl -s -X DELETE $PROVENANCE_API/v1/mandate/policies \
-H "Authorization: Bearer $PROVENANCE_KEY"
await prov.mandate.policies.reset();
prov.mandate.policies.reset()
{
"object": "policy",
"is_default": true
}
Errors you might see
| Error | Cause | Fix |
|---|---|---|
400 parameter_ on a grant | A cap or budget of 0, or a sub-grant wider than its parent | Send positive amounts no wider than the parent grant. |
400 policy_ | A rule names an unknown fact, operator or list | Simulate first: it reports the same problem without saving. |