# Set an agent's defaults

Tell each of your agents when to ask the person, as a share of the budget they granted, how far over their limit to ask before refusing, and how far over their usual spend to ask. The person who grants still sets the dollar amounts.

Use this when you run agents for other people and you can't guess each person's budget. You set up to three percentages per agent. The person who grants sets the amounts, and your percentages sit on top of whatever they chose.

**Before you begin:** [register your agents](https://provenanceauth.com/docs/mandate/guides/execution-binding.md) and name the agent (`agent_id`) on each grant. Export the sandbox account key.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

## 1. Save the defaults

[`PUT /v1/mandate/agents/{id}/defaults`](https://provenanceauth.com/docs/api/agents.md#put-v1-mandate-agents-id-defaults) replaces the agent's defaults. A key you leave out, or send as `null`, is cleared.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/mandate/agents \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "Rooms" }' > agent.json
export AGENT_ID=$(jq -r '.id' agent.json)
curl -s -X PUT $PROVENANCE_API/v1/mandate/agents/$AGENT_ID/defaults \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "ask_above": { "percent_of_budget": 20 }, "over_limit": { "percent": 20 } }'
```

**Node**

```ts
const agent = await prov.mandate.agents.create({ name: "Rooms" });
const defaults = await prov.mandate.agents.setDefaults(agent.id, {
  askAbove: { percentOfBudget: 20 },
  overLimit: { percent: 20 },
});
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
headers = {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
agent = httpx.post(f"{api}/v1/mandate/agents", headers=headers, json={"name": "Rooms"}).json()
defaults = httpx.put(
    f"{api}/v1/mandate/agents/{agent['id']}/defaults",
    headers=headers,
    json={"ask_above": {"percent_of_budget": 20}, "over_limit": {"percent": 20}},
).json()
```

```json
{
  "object": "agent_defaults",
  "agent_id": "agt_01M83TWN1D877K95BKP2JY70PB",
  "ask_above": { "percent_of_budget": 20 },
  "over_limit": { "percent": 20 },
  "over_usual": null,
  "workspace_default": { "over_limit": { "percent": 20 } },
  "usual_spend": { "window_days": 90, "min_purchases": 5 },
  "updated_at": "2026-11-23T09:13:15.057Z"
}
```

| Field | What it does | Forms |
| --- | --- | --- |
| `ask_above` | A purchase over this line asks a person. The line is under the grant's own limit: it always asks and never refuses | `{ "percent_of_budget": 20 }` (over 0, up to 100) or `{ "amount": 75 }` |
| `over_limit` | How far past a limit a person is still asked before the purchase is refused. It applies to the limit a purchase and to a budget | `{ "percent": 20 }` (0 to 1000) or `{ "amount": 50 }` |
| `over_usual` | A purchase this far over the person's usual spend in its category asks a person. It always asks and never refuses, and does nothing until the person has five purchases in that category (step 4) | `{ "percent": 50 }` (over 0, up to 1000); a percentage only |

A share of the budget needs a budget: on a grant with no `budget_amount`, `percent_of_budget` draws no line. An amount is in the grant's currency.

## 2. Know the order they apply in

For each purchase, the nearest setting wins:

1. The person's grant: its own `constraints.over_limit`, then each grant above it.
2. The defaults of the agent holding that grant.
3. Your workspace default ([`PUT /v1/mandate/settings/delegation`](https://provenanceauth.com/docs/api/grants.md#put-v1-mandate-settings-delegation)), which starts at 20%.

An agent with no defaults changes nothing. `workspace_default` on the response is what applies while `over_limit` is null.

## 3. See what a purchase over the line gets

Grant the agent a budget of 400 USD a month. With `ask_above` at 20%, the line is 80: a stay of 60 passes, and one of 90 waits for the person.

**curl**

```bash
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_id\": \"$AGENT_ID\",
    \"purpose\": \"Lisbon trip\",
    \"constraints\": { \"budget_amount\": 400, \"budget_window\": \"month\", \"currency\": \"USD\", \"expires_at\": \"2027-12-31T23:59:59Z\" }
  }" > grant.json
export MANDATE_TOKEN=$(jq -r '.mandate_token' grant.json)
curl -s -X POST $PROVENANCE_API/v1/mandate/intents \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{
    \"action_description\": \"Book Hotel Alfama, 1 night: \$90.00\",
    \"agent_session_id\": \"sess_rooms_1\",
    \"device_id\": \"dev_00000000000000000000000000000001\",
    \"mandate_token\": \"$MANDATE_TOKEN\"
  }" > intent.json
export INTENT_TOKEN=$(jq -r '.intent_token' intent.json)
curl -s -X POST $PROVENANCE_API/v1/mandate/assessments \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{
    \"intent_token\": \"$INTENT_TOKEN\",
    \"action_description\": \"Book Hotel Alfama, 1 night: \$90.00\",
    \"context\": { \"transaction_amount\": 90, \"currency\": \"USD\" }
  }"
```

**Node**

```ts
const grant = await prov.mandate.grants.create({
  deviceId: "dev_00000000000000000000000000000001",
  agentId: agent.id,
  purpose: "Lisbon trip",
  constraints: { budgetAmount: 400, budgetWindow: "month", currency: "USD", expiresAt: "2027-12-31T23:59:59Z" },
});
const action = "Book Hotel Alfama, 1 night: $90.00";
const intent = await prov.mandate.intents.create({
  actionDescription: action,
  agentSessionId: "sess_rooms_1",
  deviceId: "dev_00000000000000000000000000000001",
  mandateToken: grant.mandateToken,
});
const result = await prov.mandate.assessments.create({
  intentToken: intent.intentToken,
  actionDescription: action,
  context: { transaction_amount: 90, currency: "USD" },
});
```

**Python**

```python
grant = httpx.post(f"{api}/v1/mandate/grants", headers=headers, json={
    "device_id": "dev_00000000000000000000000000000001",
    "agent_id": agent["id"],
    "purpose": "Lisbon trip",
    "constraints": {"budget_amount": 400, "budget_window": "month", "currency": "USD", "expires_at": "2027-12-31T23:59:59Z"},
}).json()
action = "Book Hotel Alfama, 1 night: $90.00"
intent = httpx.post(f"{api}/v1/mandate/intents", headers=headers, json={
    "action_description": action,
    "agent_session_id": "sess_rooms_1",
    "device_id": "dev_00000000000000000000000000000001",
    "mandate_token": grant["mandate_token"],
}).json()
result = httpx.post(f"{api}/v1/mandate/assessments", headers=headers, json={
    "intent_token": intent["intent_token"],
    "action_description": action,
    "context": {"transaction_amount": 90, "currency": "USD"},
}).json()
```

The answer is `valid: false` with `reason: "approval_pending"` and the line it went past. `source: "agent_default"` says the line is yours, not a limit the person set:

```json
{
  "valid": false,
  "reason": "approval_pending",
  "step_up_reason": "delegation_over_limit",
  "over_limit": { "kind": "amount", "grant_id": "grt_01M83TQG28VHNMBFTP913MAWWF", "limit": 80, "amount": 90, "currency": "USD", "lifts": [], "source": "agent_default" }
}
```

Once the person approves, the same verify answers `valid: true` and the purchase is spent once. A store that checks the cart with a [checkout assessment](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) asks the shopper the same way.

## 4. Ask when a purchase is over the person's usual

`over_usual` compares a purchase with what this person usually spends in the same category. It is off until you set it:

**curl**

```bash
curl -s -X PUT $PROVENANCE_API/v1/mandate/agents/$AGENT_ID/defaults \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "ask_above": { "percent_of_budget": 20 }, "over_usual": { "percent": 50 } }'
```

**Node**

```ts
await prov.mandate.agents.setDefaults(agent.id, { askAbove: { percentOfBudget: 20 }, overUsual: { percent: 50 } });
const usual = await prov.mandate.grants.usualSpend(grant.id);
```

**Python**

```python
httpx.put(
    f"{api}/v1/mandate/agents/{agent['id']}/defaults",
    headers=headers,
    json={"ask_above": {"percent_of_budget": 20}, "over_usual": {"percent": 50}},
)
usual = httpx.get(f"{api}/v1/mandate/grants/{grant['id']}/usual_spend", headers=headers).json()
```

- **Usual spend** is the median of the person's purchases in that category over the last 90 days, under every grant they gave your account. The category comes from the merchant category code: the one a payment integration reported, else the one the store or `context.mcc` declared, grouped as in the [spend summary](https://provenanceauth.com/docs/mandate/guides/see-what-agents-spent.md).
- **The line** is the usual spend plus your percentage. With a usual of 40 USD and `over_usual` at 50%, a purchase of 55 passes and one of 65 waits for the person.
- **Before five purchases** in a category there is no baseline, and `over_usual` does nothing there. It doesn't fall back to the budget: the grant's limits, `ask_above` and `over_limit` work as they always do.
- **When both lines are passed**, a limit the person set names the ask first, then `ask_above`, then `over_usual`.

An ask from usual spend carries `source: "usual_spend"`, with `limit` set to the line. [`GET /v1/mandate/grants/{id}/usual_spend`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id-usual-spend) shows the person's usual spend per category and whether each is a baseline yet:

Each row of `categories`:

| Field | What it is |
| --- | --- |
| `category`, `label` | The category of spend (`dining`, Dining) |
| `currency` | The currency of these purchases; each currency has its own figure |
| `median` | The person's usual spend: the median purchase in the last 90 days |
| `purchases` | How many purchases the median is taken over |
| `baseline` | `true` from five purchases; until then `over_usual` asks nothing in this category |

In the console, **Mandate → Agents** opens an agent's drawer with **Your defaults**: ask above and over their limit as a number with percent or amount, over their usual as a percent, and what people granted beside it. A grant's drawer under **Mandate → Grants** lists the person's usual spend per category, and says which categories aren't checked yet.

## Errors you might see

| Error | Why |
| --- | --- |
| `parameter_invalid` | `over_usual` was sent as an amount, a share of the budget is 0 or over 100, or a default has both forms |
| `usual_spend_unavailable` | The person's purchases couldn't be read for [`GET /v1/mandate/grants/{id}/usual_spend`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id-usual-spend); try again shortly |
| `resource_missing` | The agent isn't one of this account's |

## See also

- [Set limits and policy](https://provenanceauth.com/docs/mandate/guides/set-limits-and-policy.md)
- [Sub-agent limits](https://provenanceauth.com/docs/mandate/guides/subagent-limits.md)
- [See what agents spent](https://provenanceauth.com/docs/mandate/guides/see-what-agents-spent.md)
