# Hand off to outside agents

Hand part of a grant to an agent your account doesn't run, bound to that agent's key. The grantor is asked first and sees who will hold it, what it allows, and whether stores may check it offline.

Use this when your agent needs an agent run by another company to act for it: an airline's booking agent holding a seat, or a hotel's agent placing a deposit. The outside agent gets its own narrower grant, bound to its key, and the person or company that granted yours says yes first.

The receiver can be an agent registered in another Provenance account, or any agent that holds a P-256 key. A registered agent shows the grantor its registry name and operator. An agent named only by its key shows the name and origin it declared, marked unverified.

**Before you begin:** the receiver gives you its public key (`generateHolderKey` in `@provenanceauth/rails/mandates` makes one). Every grant handed outside the account is bound to that key, so a copied token is useless to anyone else (your account can lift that for one registered agent, step 7). See [bind a grant to its holder](https://provenanceauth.com/docs/mandate/guides/bind-a-grant-to-its-holder.md).

## 1. Ask with `receiver`

Call [`POST /v1/mandate/grants/{id}/delegate`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants-id-delegate) with `receiver` and the receiver's `holder_key`. The call answers `202` with an `external_handoff`, and no grant exists yet:

**curl**

```bash
export GRANT_ID=$(curl -s $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" \
  -H "Content-Type: application/json" \
  -d '{ "device_id": "dev_00000000000000000000000000000001", "purpose": "Book Maya'"'"'s Lisbon trip", "constraints": { "max_amount": 1200, "budget_amount": 2400, "budget_window": "month", "expires_at": "2027-12-31T23:59:59Z" } }' | jq -r .id)

curl -s $PROVENANCE_API/v1/mandate/grants/$GRANT_ID/delegate \
  -H "Authorization: Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" \
  -H "Content-Type: application/json" \
  -d '{ "agent_session_id": "sess_valet_flights_1", "purpose": "Hold seat 14C on TP1351", "constraints": { "max_amount": 600, "budget_amount": 600 }, "receiver": { "kind": "key", "name": "SkyDesk Seats", "origin": "https://seats.skydesk.example" }, "holder_key": { "kty": "EC", "crv": "P-256", "x": "NeVHu4qeD40iEEgSDcTm26Y0xApkjq41T6BuENVl0js", "y": "qS59-GAPcl0bJ-yYFvPJA3omsU9DJFedMw4rou5cXo8" } }'
```

**Node**

```ts
const asked = await provenance.mandate.grants.handOff(grantId, {
  agentSessionId: "sess_valet_flights_1",
  purpose: "Hold seat 14C on TP1351",
  constraints: { maxAmount: 600, budgetAmount: 600 },
  receiver: { kind: "key", name: "SkyDesk Seats", origin: "https://seats.skydesk.example" },
  holderKey: receiverPublicJwk,
});
// asked.object === "external_handoff", asked.status === "pending"
```

For an agent registered in another account, send `{ "kind": "provenance_agent", "agent_id": "agt_…" }`. An agent registered in your own account isn't an outside agent: delegate to it with `agent_id`.

The child is checked as any delegation is before anyone is asked: it can only narrow its parent. An outside agent can't hand its grant on, so leave out `max_depth`.

## 2. The grantor answers

The approval goes to whoever granted the grant at the top of the chain:

| The top grant | Who answers |
| --- | --- |
| Granted by a person with their passkey | That person, with the same passkey, through their approval channels |
| Granted by the account (an account key, no passkey) | The account's people, as an over-limit approval is |

The approval shows the receiver, the task, the limits, the expiry, that the receiver can't hand it on, and whether stores may check it offline with what that costs. `approval_id` is the approval; the account reads the hand-off at `status_url` ([`GET /v1/mandate/external_handoffs/{id}`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-external-handoffs-id)).

## 3. Send the same call with `handoff_id`

After the yes, send the same body again with `handoff_id`. It answers `201` with the bound grant and its token, which you pass to the receiver:

```ts
const result = await provenance.mandate.grants.handOff(grantId, { ...params, handoffId: asked.id });
if (result.object === "grant") sendToReceiver(result.mandateToken);
```

| Answer | Means |
| --- | --- |
| `202` | Still waiting for the grantor |
| `201` | The grant, bound to the receiver's key (`holder_jkt`, `cnf.jkt`), with `external` naming the hand-off |
| `403 external_delegation_declined` | The grantor said no, or didn't answer before the approval expired |
| `409 external_delegation_used` | This hand-off already minted its grant |
| `400` on `handoff_id` | The body isn't what the grantor was asked about |

The grant can't be handed on (`max_depth` is its own depth). Revoking anything above it stops it, and the receiver sees that at [`GET /v1/public/grants/{id}/status`](https://provenanceauth.com/docs/api/grants.md#get-v1-public-grants-id-status). A registered receiver that its maker suspends stops too.

## 4. Choose offline checks

`offline_checks` says whether stores may check the grant offline:

| Value | What the token says | What it costs |
| --- | --- | --- |
| `refused` | `status_check: "online"` | Every verifier checks the grant's status online before it accepts it. Every purchase counts against the budget, and a revoke stops it at once |
| `allowed` | Nothing extra | Stores may check it with the JWKS alone. Purchases at those stores aren't counted against the budget, and they learn of a revoke only when they check online |

Left out, a hand-off allows offline checks only when the child's budget (its own, or the tightest above it) is at or under the account's `external_online_above`. That is 0 by default, so every hand-off defaults to online checks.

The offline verifiers answer `status_check_required` for a grant that says `status_check: "online"` and was checked offline:

```ts
import { verifyMandate } from "@provenanceauth/rails/mandates";

const r = await verifyMandate(mandateToken, { jwks, holder, online: true, apiBase: "https://api.provenanceauth.com" });
```

In Python, pass `online=True` to `verify_mandate`. In Go, read the status with `FetchMandateStatus` and pass it to `VerifyMandateOnline`.

## 5. Turn hand-offs off

An admin key sets the account's settings with [`PUT /v1/mandate/settings/delegation`](https://provenanceauth.com/docs/api/grants.md#put-v1-mandate-settings-delegation):

- `external`: `ask` (the default) asks the grantor first; `refuse` refuses every hand-off outside the account with `403 external_delegation_refused`, and nobody is asked.
- `external_online_above`: the budget at or under which a hand-off that doesn't say allows offline checks.

## 6. Skip the ask for agents you trust

A trusted agent gets its hand-offs without the ask. There are two lists:

- **Your company's**, in Settings › Agent teams or with [`POST /v1/mandate/trusted_agents`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-trusted-agents) (an admin key). It covers hand-offs under grants your account issued.
- **A person's own**, in their home under Security › Trusted agents. It covers hand-offs under grants that person signed with their passkey.

An entry names the agent one of two ways:

| `receiver.kind` | Also send |
| --- | --- |
| `provenance_agent` | `agent_id`, an agent registered in another account |
| `key` | `name`, `origin` and `holder_key`, the agent's P-256 public key |

Set `max_amount` or `budget_amount` to cap what skips. A hand-off over a cap, or without that limit at all, still asks the grantor.

```ts
await provenance.mandate.grants.addTrustedAgent({
  receiver: { kind: "key", name: "SkyDesk Seats", origin: "https://seats.skydesk.example", holderKey: skydesk.publicJwk },
  maxAmount: 600,
});
```

A hand-off to a trusted agent answers `201` on the first call. The grant is still bound to the agent's key and checked like any other. The hand-off has `approval_id: null` and names the entry in `trusted_agent_id`, and the ledger row says so.

## 7. Choose holder binding per agent

By default your own agents get bearer grants and outside agents get grants bound to their key. Change either for one agent with [`PUT /v1/mandate/holder_bindings/{agent_id}`](https://provenanceauth.com/docs/api/grants.md#put-v1-mandate-holder-bindings-agent-id) (an admin key), or in Settings › Agent teams:

- `required`: every grant to this agent of yours, on grant or delegate, must carry `holder_key`.
- `not_required`: a hand-off to this outside registered agent may leave `holder_key` out, so its grant is a bearer grant.

Deleting the setting puts the agent back on the default. An agent named only by its key is always bound, because the key is how it's named.

## For the receiving account

When the receiver is an agent registered in your account, your account gets a record of each grant handed to it. Subscribe a webhook endpoint to `mandate.incoming_grant.received` and `mandate.incoming_grant.revoked`, and read the records with [`GET /v1/mandate/incoming_grants`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-incoming-grants):

```ts
const { data } = await provenance.mandate.grants.listIncomingGrants({ agentId });
// data[0].grantId, .chain, .purpose, .constraints, .holderJkt, .offlineChecks, .status
```

| Event | Sent when |
| --- | --- |
| `mandate.incoming_grant.received` | A grant is minted for your agent; it names the incoming grant, the grant and its purpose |
| `mandate.incoming_grant.revoked` | A revoke reaches the grant: its own, or one above it, named in `stopped_by` |

A record holds what the grant's token already carries: the grant and chain ids, the purpose, the limits, the holder key and whether offline checks are allowed. The grant itself stays with the account that handed it, so [`GET /v1/mandate/grants/{id}`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id) answers 404 for you. An agent named only by its key gets no record; it checks [`GET /v1/public/grants/{id}/status`](https://provenanceauth.com/docs/api/grants.md#get-v1-public-grants-id-status).

**Availability:** every plan that has grants. A hand-off counts against the grant allowance when its grant is minted, and the ask is billed as the approval it is. Revocation, status checks and offline verification are free. A receiver is named by a P-256 key, and an outside agent can't hand its grant on.

## Errors you might see

| Code | What to do |
| --- | --- |
| `external_delegation_refused` | The account's `external` setting is `refuse`. Delegate inside the account, or set it to `ask`. |
| `external_delegation_declined` | The grantor said no or didn't answer in time. Ask again without `handoff_id` if they should see it again. |
| `external_delegation_used` | The hand-off already minted its grant. Use that grant, or start a new hand-off. |
| `parameter_invalid` (`holder_key`) | Send the receiver's P-256 public key: every grant handed outside the account is bound to it, and your account may require it for one of its own agents. |
| `parameter_invalid` (`handoff_id`) | Send the same body the grantor was asked about, with the same `holder_key` and `offline_checks`. |
| `delegation_exceeds_parent` | Narrow the child: a hand-off can't allow more than the grant it comes from. |

## See also

- [A2A delegation v1](https://provenanceauth.com/docs/a2a/delegation/v1.md): the grant over A2A
- [Agent tools](https://provenanceauth.com/docs/provenance-mcp/agent-tools.md#act-under-a-grant-another-agent-handed-over): the grant over MCP, in a request's `_meta` under `com.provenanceauth/grant`
- [Bind a grant to its holder](https://provenanceauth.com/docs/mandate/guides/bind-a-grant-to-its-holder.md)
- [Check an agent's grant](https://provenanceauth.com/docs/mandate/guides/check-another-agents-authority.md)
- [Delegate to sub-agents](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md)
