# Propose a plan of subagents

Hand part of a person's network grant to registered subagents through one plan the person reviews, revise it, read the webhooks and stop relying on a subagent the person stopped.

When your agent holds a person's [network grant](https://provenanceauth.com/docs/mandate/concepts/network-grants.md) and wants other agents to do part of the work, it proposes a delegation plan: the task in one line and, for each subagent, its purpose, its budget and any narrower limits. The person reviews the plan once, changes it if they want, and can see and stop every subagent later.

**Before you begin:** your grant request proposed hand-on (`proposed.hand_on: true`) and the person kept it, so the grant reads `hand_on: "ask"`. Each subagent is a registered agent with an active signing key. A subagent from another maker is allowed; the person sees its maker's name.

## 1. Ask for hand-on in the grant request

```json
{
  "agent_id": "agt_scout",
  "proposed": { "max_amount": 1500, "budget_amount": 2400, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z", "hand_on": true }
}
```

`hand_on` isn't a limit, so it leaves the grant's constraints and token as they were. Without it, a plan is refused with 403 `delegation_not_allowed`.

## 2. Propose the plan

[`POST /v1/mandate/network_grants/{id}/delegation_plans`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-network-grants-id-delegation-plans) with the task and the subagents:

```json
{
  "task": "Lisbon trip, Dec 9 to 13",
  "helpers": [
    {
      "key": "flights", "agent_id": "agt_flights", "purpose": "Book the flights",
      "budget": { "amount": 1100, "allocation": "reserved", "at_limit": "stop" }
    },
    {
      "key": "rooms", "agent_id": "agt_rooms", "purpose": "Book the hotel",
      "budget": { "amount": 900, "allocation": "shared", "at_limit": "ask", "ask_up_to": { "percent": 10 } },
      "limits": { "allowed_stores": ["https://casamarlinde.example"] }
    }
  ]
}
```

Each subagent's `budget` has its `amount` and two settings ([budgets](https://provenanceauth.com/docs/mandate/concepts/grants.md#budgets)):

| Field | Values | What it means |
| --- | --- | --- |
| `allocation` | `reserved` | Set aside from the grant. Nobody else can spend it. |
|  | `shared` (default) | Drawn from what the grant has left. |
| `at_limit` | `stop` | Past its amount the order is refused (`over_helper_limit`). |
|  | `ask` (default for `shared`) | Past its amount the order asks the person, up to `ask_up_to` (20% by default; `null` for any amount the grant has room for), then is refused. |
|  | `continue` | Past its amount the order goes through without asking while the grant has room. |

A subagent can never pass what the grant above it has left.

**Merchant lock.** `limits.allowed_stores` locks a subagent to up to a few stores (the person's page takes 5). At any other store its order is refused with `outside_merchant_lock`, with no approval and no adjust link, so nothing waits for the person. A person's own grant with `allowed_stores` still asks at another store (`store_not_listed`). The person sees the lock as the subagent's Merchant row and can add, narrow or remove it while reviewing. `limits.allowed_categories` is the Category row.

Every subagent is checked against the grant: never wider on any limit, at most 4 levels below the person's grant and 50 live subagents per grant, and the reserved budgets with what was already spent fit the budget. A plan that needs more than the grant is refused unless it sets `requests_raise`, which the person always reviews and accepts with their passkey.

The answer is **201** with `children` (each subagent's grant and, for your own agents, its `network_mandate` token) when the person's review setting accepts the plan at once, or **202** with `review.url` when it waits. Send the person that link, for example as "Change the plan". A proposed plan expires after 24 hours unanswered and is never accepted by silence.

## 3. Revise it

- [`POST /v1/mandate/delegation_plans/{id}/revisions`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-delegation-plans-id-revisions) sends the whole next list, keys kept. A revision that only tightens (removes a subagent, lowers a budget, moves `at_limit` toward `stop`, adds or narrows a merchant or category lock, shortens dates) applies at once; anything else waits for the person while the accepted version keeps running.
- [`POST /v1/mandate/network_grants/{id}/delegate`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-network-grants-id-delegate) adds one subagent to the live plan.
- [`POST /v1/mandate/delegation_plans/{id}/withdraw`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-delegation-plans-id-withdraw) withdraws a version still waiting. A newer proposal replaces an older one.

## 4. Buy under a subagent's grant

The subagent buys with [`POST /v1/mandate/network_orders`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-network-orders) and its own grant token. Each order walks the chain, so a stop above it takes effect on the next order. A subagent from another maker gets its token on its own maker's webhook.

| Field on a refusal | Meaning |
| --- | --- |
| `reason: parent_stopped` | A grant above is stopped, paused or expired, or an agent above is suspended |
| `reason: over_helper_limit` | Past the subagent's amount, with `at_limit: stop` or past `ask_up_to` |
| `reason: outside_merchant_lock` | The subagent is locked to other stores |
| `stopped_by` | `person`, `maker`, `parent`, `agent_suspended` or `expired` |
| `stopped_grant_id` | The grant that stopped it |

## 5. Handle the webhooks

| Event | When |
| --- | --- |
| `mandate.delegation_plan.proposed` | The plan waits for the person |
| `mandate.delegation_plan.accepted` | Accepted, by the person or at once (`edited_by`, `decided_via`, the subagents as saved) |
| `mandate.delegation_plan.changed` | The person saved changes (`changes`: one line each) |
| `mandate.delegation_plan.declined`, `.expired` | Work on under your own grant |
| `mandate.network_grant.delegated` | A subagent grant was minted |
| `mandate.network_grant.stopped` | The person stopped a subagent and everything below it (`stopped_below`) |

The person chooses how your plans are reviewed, per agent or as their default. Your call reads the result: 201 when
accepted, 202 when waiting.

| Review mode | What happens to your plan |
| --- | --- |
| `prompt` (the default) | It waits for the person |
| `auto_accept` | Accepted at once if it fits the grant |
| `digest` | Accepted at once; the person sees it in one daily summary |
| `first_time` | Waits only when it names a subagent not accepted before |

A plan with `requests_raise`, or naming a subagent from a maker the person never approved, always waits. When the person
raises a subagent's budget from now on, the plan gets a new version and you get `mandate.delegation_plan.changed`.

The person can also change a running plan themselves: add or remove a subagent, or change a budget, its two settings, its category or its merchants. The plan gets a new
version with `edited_by: person`, new subagents' grants are minted, removed ones stop, and you get
`mandate.delegation_plan.changed`. Read the plan again before your next revision: a revision on an older version is
409 `plan_changed`.

## What to check

- Read the grant with [`GET /v1/mandate/network_grants/{id}`](https://provenanceauth.com/docs/api/network.md#get-v1-mandate-network-grants-id):

| Field | On |
| --- | --- |
| `hand_on`, `plan_id`, `helper_count`, `plan_pending` | A grant that may hand on |
| `parent_id`, `budget` (`allocation`, `at_limit`, `ask_up_to`), `purpose`, `depth` | A subagent grant |

- Pricing: a plan the person is asked to review counts as one confirmation. Plans accepted at once and the subagent grants are free; the orders subagents make are metered as network orders.

## Errors you might see

| Code | Why | Fix |
| --- | --- | --- |
| `delegation_not_allowed` (403) | The grant has no hand-on | Ask for `hand_on` in the grant request |
| `delegation_exceeds_parent` (400) | A subagent is wider than the grant, or the budgets don't fit | Lower the field in `param` |
| `helper_not_verified` (400) | The agent isn't registered or has no active signing key | Add a signing key to the agent |
| `delegation_depth_exceeded`, `delegation_limit_reached` | Past 4 levels or 50 live subagents | Stop subagents whose work is done |
| `plan_closed` (409) | The version was already decided | Read the plan again |

## See also

- [Network grants](https://provenanceauth.com/docs/mandate/concepts/network-grants.md)
- [Give subagents their own limits](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md), for company grants
- [Near-limit notices](https://provenanceauth.com/docs/mandate/guides/near-limit-notices.md)
