Mandate · Guide
Connect an agent
Use a network grant when your agent shops for people at many stores. The person grants your agent one set of limits, and your agent buys inside them without asking each time.
Before you begin: register the agent and give it an Identify signing key. Network grants are for verified agents only.
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
1. Register the agent and its signing key
export AGENT_ID=$(curl -s -X POST $PROVENANCE_API/v1/mandate/agents -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" -d '{ "name": "cartwise", "category": "shopping_agent" }' | jq -r .id)
curl -s -X POST $PROVENANCE_API/v1/identify/agents/$AGENT_ID/signing_keys \
-H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
-d '{ "jwk": { "kty": "OKP", "crv": "Ed25519", "x": "G_STrQBvTD7Bi8OjlNnLcKPPiPp03Vh0sJKTMG7QzFY" } }'
const headers = { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" };
const agent = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/agents`, { method: "POST", headers, body: JSON.stringify({ name: "cartwise", category: "shopping_agent" }) })).json();
await fetch(`${process.env.PROVENANCE_API}/v1/identify/agents/${agent.id}/signing_keys`, {
method: "POST", headers, body: JSON.stringify({ jwk: { kty: "OKP", crv: "Ed25519", x: "G_STrQBvTD7Bi8OjlNnLcKPPiPp03Vh0sJKTMG7QzFY" } }),
});
import os
import httpx
api, h = os.environ["PROVENANCE_API"], {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
agent = httpx.post(f"{api}/v1/mandate/agents", headers=h, json={"name": "cartwise", "category": "shopping_agent"}).json()
httpx.post(f"{api}/v1/identify/agents/{agent['id']}/signing_keys", headers=h, json={"jwk": {"kty": "OKP", "crv": "Ed25519", "x": "G_STrQBvTD7Bi8OjlNnLcKPPiPp03Vh0sJKTMG7QzFY"}})
{
"object": "agent_signing_key",
"status": "active"
}
2. Ask the person
POST / takes the limits you ask for (the example registers the signing key first, as in step 1). Send the person to grant_url; they see your agent, your company and the limits in plain words, lower any of them, and grant with their passkey.
curl -s -X POST $PROVENANCE_API/v1/identify/agents/$AGENT_ID/signing_keys -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" -d '{ "jwk": { "kty": "OKP", "crv": "Ed25519", "x": "G_STrQBvTD7Bi8OjlNnLcKPPiPp03Vh0sJKTMG7QzFY" } }' > /dev/null
curl -s -X POST $PROVENANCE_API/v1/mandate/grant_requests \
-H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
-d '{ "agent_id": "'$AGENT_ID'", "proposed": { "max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z" }, "return_url": "https://cartwise.example/connected" }'
const request = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/grant_requests`, {
method: "POST", headers,
body: JSON.stringify({ agent_id: agent.id, proposed: { max_amount: 50, budget_amount: 200, budget_window: "month", currency: "USD", expires_at: "2027-06-30T00:00:00Z" }, return_url: "https://cartwise.example/connected" }),
})).json();
request = httpx.post(f"{api}/v1/mandate/grant_requests", headers=h, json={
"agent_id": agent["id"],
"proposed": {"max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z"},
"return_url": "https://cartwise.example/connected",
}).json()
{
"object": "network_grant_request",
"status": "pending"
}
3. Collect the grant
When the person grants it, the mandate.network_grant.granted webhook carries network_mandate (the token), or GET / returns it. The token is an ES256 network-mandate+jwt with aud: provenance-network; its sub is the person, pairwise for your account. Keep it like a credential.
4. Buy under it
POST / takes the token, the store's cart as checkoutBinding(order) and the store's origin as aud:
import { checkoutBinding } from "@provenanceauth/rails/checkout";
const order = checkoutBinding({ order_id: "ord_88213", total: 3800, currency: "usd", merchant_id: "m_quillstack", origin: "https://shop.quillstack.example",
items: [{ sku: "nb-linen", name: "Linen notebook", quantity: 2, unit_amount: 1900 }] });
const res = await prov.mandate.network.createOrder({ networkMandate, order, aud: order.origin });
if (res.result === "authorized") {
// Send res.intentToken in the store's Provenance-Intent header. It works for 10 minutes.
} else if (res.result === "approval_required") {
// Show res.approval.approveUrl to the person as-is; once they approve, authorize again with approvalId.
}
From an MCP client, the request_grant and buy_under_grant tools do the same (agent tools).
Send agent_session with each authorize call so the person sees each run of your agent as its own session, and can stop or limit one without turning your agent off. A stopped session's calls are refused with session_stopped, and its reserved orders are released.
agent_session.idstringRequired- Your ID for this run. It's stored hashed.
agent_session.clientobjectnameandversion: the label the person sees.agent_session.workspacestring- What this run works on, shown to the person.
Errors you might see
| Code or reason | What to do |
|---|---|
network_ | Register a signing key for the agent (step 1). |
over_, over_ | Show approval. to the person, then authorize again with approval_. |
network_ | The person revoked or paused it, or it expired. Ask again. |
store_ | The person or the grant blocks this store. |
session_, session_ | The person stopped or limited this session. Start a new session, or stay within its limits. |
blocked_ | The person blocked your agent. Stop asking them; only they can unblock it. |
A response can also carry notes: short notes and questions from the person. See receive notes from people.