# AI agents and treasury automation

> Let an automated agent watch balances, propose conversions and make permitted payments: a least-privilege service account, policy rules that hold large operations for a person's approval, idempotent writes, an audit trail that names the agent, and a kill switch. Vendor-neutral.

Source: https://business-api-docs.youhodler.com/use-cases/ai-treasury-agent

> **Status: In the API.** Every call on this page is in the public API contract.

You want software to do routine treasury work: notice that the dollar buffer is
low, propose converting surplus pesos, move money between your accounts, pay a
supplier you already pay every month. You do not want that software to be able
to empty the treasury, approve its own requests, or act without a trace.

This guide shows how to run such an agent on the Business API. It is for
automation and finance teams, and for the developer who builds the agent. The
"agent" can be a scheduled job, a rules engine or a language model: the
platform treats them all the same, and nothing here depends on a particular
AI vendor or model.

The outcome:

- The agent has its **own identity**, a service account that can read and
propose, or execute within limits, and nothing more.
- **Policy rules on the platform**, not just checks inside the agent, hold
anything large for a person to approve and refuse anything above a ceiling.
- Every write carries an **idempotency key**, so a retry cannot pay twice.
- The **audit trail** names the agent as the initiator and the person as the
approver.
- One call **switches the agent off**.

A working example: [treasury-agent](/examples#treasury-agent)
([download the zip](/example-apps/treasury-agent.zip)) keeps a USD buffer
topped up from surplus ARS, with a decision log and a mock mode you can run
without credentials.

## How it works

The agent proposes, the platform decides and executes, and people approve what
the policy holds.

```mermaid
sequenceDiagram
  participant Agent as Agent (service account)
  participant API as Business API
  participant Policy as Policy rules
  participant Person as Approver (console)
  Agent->>API: Read balances, price and conversion preview
  Agent->>API: POST /conversions with Idempotency-Key
  API->>Policy: Evaluate active rules for this conversion
  Policy-->>API: Require one approval
  API-->>Agent: 202, status pending_approval, approval_ref
  Agent->>Agent: Record the approval id and stop
  API-->>Person: Case appears under Approvals
  Person->>API: Approve, with MFA step-up
  API->>API: Execute the conversion as the agent
  API-->>Agent: Event operations.conversion.settled.v1
  Agent->>API: GET the conversion, report the result
```

1. The agent reads balances, an indicative price and a conversion preview.
None of these move money.
2. It submits the conversion with an `Idempotency-Key`.
3. The platform evaluates the active policy rules for the operation.
4. A rule requires a person's approval, so the conversion stops at
`pending_approval` and the response carries an `approval_ref`.
5. The agent records the approval reference and stops. It does not resubmit.
6. The approval case appears in the console under **Approvals**.
7. A person who is allowed to decide approves it, with an MFA step-up.
8. The platform executes the conversion under the agent's identity.
9. The platform publishes `operations.conversion.settled.v1` (or `failed`).
10. The agent reads the conversion and reports the result.

Small operations under the rule's threshold skip steps 4 to 7 and execute
straight away. Operations a deny rule matches are refused at step 3 with
`422`.

## Before you start

- **Sandbox access.** An enterprise, an account holding funds, and a person
who can create service accounts, roles and policy rules. Those setup rights
(`service_accounts.create`, `roles.create`, `role_assignments.create`,
`policies.create`, `policies.manage`) belong to that person, never to the
agent.
- **Worth reading first:** [Identity](/concepts/identity),
[Access](/concepts/access),
[Policies and approvals](/concepts/policies-and-approvals),
[Operations](/concepts/operations) and
[Idempotency and concurrency](/concepts/idempotency-and-concurrency).
- **The treasury calls themselves** (balances, conversions, transfers,
payouts, reconciliation) are explained in
[Smart treasury and international payments](/use-cases/treasury-and-international-payments).
This page adds what changes when software, not a person, makes them.

## 1. Give the agent its own identity

Create one service account per agent. Never let an agent use a person's
credentials or share a key with another integration: the audit trail can only
be as precise as the identity behind each call. In the console, service
accounts are under **API Keys**.

Bundle the capabilities into a role, then provision the account with that role
in one call. Each capability below is the `x-required-capability` of the
operation the agent calls.

### A read-and-propose agent

It watches and suggests; a person executes the suggestion in the console.

| Capability | Lets the agent call |
| --- | --- |
| `accounts.read` | `GET /master-accounts/{master_account_id}/balances`, `GET /client-accounts/{client_account_id}/balances`, `GET /master-accounts`, `GET /client-accounts` |
| `conversions.read` | `GET /conversions`, `GET /conversions/{conversion_id}` |
| `internal_transfers.read` | `GET /internal-transfers`, `GET /internal-transfers/{internal_transfer_id}` |
| `withdrawals.read` | `GET /withdrawals`, `GET /withdrawals/{withdrawal_id}` |
| `deposits.read` | `GET /deposits`, `GET /deposits/{deposit_id}` |
| `withdrawal_destinations.read` | `GET /withdrawal-destinations` |
| `events.read` | `GET /events`, `GET /events/{event_id}` |
| `approvals.read` | `GET /approvals`, `GET /approvals/{approval_id}` |

Prices and previews need no capability: `GET /prices/indicative`,
`GET /prices/assets`, `POST /fee-previews`, `POST /conversions/preview` and
`GET /conversion-pairs`. The account you ask about must still be inside the
service account's scope. `GET /me/capabilities` tells the agent what it holds.

### An agent that executes within limits

The same list, plus the create capabilities for the operations it may start:

| Capability | Lets the agent call |
| --- | --- |
| `conversions.create` | `POST /conversions` |
| `internal_transfers.create` | `POST /internal-transfers` |
| `withdrawals.create` | `POST /withdrawals` |

Add only the ones it needs: an agent that only converts gets
`conversions.create` and no payout capability. Add `conversions.manage`,
`internal_transfers.manage` or `withdrawals.manage` only if it should cancel
its own operations.

**`withdrawals.create` means "can pay any crypto address".** `POST /withdrawals`
accepts an inline crypto `destination` with a `network` as well as a
registered `destination_id`, and no policy condition matches on the
destination. Withholding `withdrawal_destinations.create` does not keep the
agent on registered destinations. Either do not grant `withdrawals.create`,
or hold every withdrawal the agent starts for a person: a `require_approval`
rule with an `initiator` condition and no amount condition (step 2).

### Never grant an agent

| Capability | Why not |
| --- | --- |
| `approvals.decide` | It could take part in approving its own proposals. The platform does not count a service account as an approver anyway. |
| `policies.create`, `policies.manage` | It could retire the rule that holds it. |
| `roles.create`, `roles.manage`, `role_assignments.create`, `role_assignments.manage` | It could grant itself more. |
| `service_accounts.create`, `service_accounts.manage`, `service_accounts.rotate_secret` | It could mint new credentials or undo its own revocation. |
| `withdrawal_destinations.create`, `withdrawal_destinations.manage` | It could add or re-enable a payout destination of its choosing. Withholding them is not enough on its own: see `withdrawals.create` above. |

### Create the role and the account

A person with the setup rights creates the role:

```http
POST https://b2b2x-sandbox.youhodler.com/api/roles
Authorization: Bearer <admin_access_token>
Idempotency-Key: role-treasury-agent-001
Content-Type: application/json

{
  "name": "Treasury agent",
  "description": "Reads balances and operations, converts and moves funds within policy limits",
  "permissions": [
    "accounts.read",
    "conversions.read",
    "conversions.create",
    "internal_transfers.read",
    "internal_transfers.create",
    "withdrawals.read",
    "withdrawals.create",
    "withdrawal_destinations.read",
    "events.read",
    "approvals.read"
  ],
  "scope_ref": "enterprises/00000000-0000-4000-8000-000000000001"
}
```

Then provisions the service account with it. Assign the role at the narrowest
scope that covers the accounts the agent manages. For an agent that runs only
your master account, grant it at the enterprise with `scope_propagation`
`self`, as below. For an agent that serves one connected account, grant it at
that connected account (API: `clients/<id>`).

> **subtree at the enterprise reaches customer money:** `subtree` at `enterprises/&lt;id&gt;` covers every connected account and client account under it. With the create capabilities above, the agent could move any customer's funds below your approval threshold. Use it only for an agent that must act on those accounts, and hold its operations with the rules in step 2.

```http
POST https://b2b2x-sandbox.youhodler.com/api/service-accounts/provision
Authorization: Bearer <admin_access_token>
Idempotency-Key: sa-treasury-agent-001
Content-Type: application/json

{
  "description": "Treasury agent",
  "parent_ref": "enterprises/00000000-0000-4000-8000-000000000001",
  "client_secret_ttl_seconds": 2592000,
  "roles": [
    {
      "role_ref": "roles/00000000-0000-4000-8000-000000000003",
      "scope_ref": "enterprises/00000000-0000-4000-8000-000000000001",
      "scope_propagation": "self"
    }
  ]
}
```

The `201` response carries `client_id`, `client_secret`, `principal_ref`
(`service-accounts/<id>`) and `role_assignments`. Three things to check:

- `role_assignment_errors` must be empty. The account is created even when a
grant fails, and the response is still `201`.
- `client_secret` appears only in this response. Store it in your secret
manager, never in the agent's prompt, code or logs. A retry with the same key
returns the account without the secret.
- `client_secret_ttl_seconds` (minimum 60) bounds how long a leaked secret
works. A person rotates it with
`POST /service-accounts/{service_account_id}/rotate-secret`.

The agent then gets its token with the client-credentials grant; see
[Authentication](/integrations/authentication). See
[Provision service account with roles](/api/reference/service-accounts/service-accounts-provision)
for every field.

## 2. Put the guardrails on the platform

Limits inside the agent help, but the agent's own code or model can be wrong.
Rules on the platform hold even then. Write them for the agent's service
account specifically with an `initiator` condition.

This rule holds every conversion the agent submits that is worth 5,000 USD or
more until one person approves it:

```http
POST https://b2b2x-sandbox.youhodler.com/api/policy-rules
Authorization: Bearer <admin_access_token>
Idempotency-Key: rule-agent-conversions-001
Content-Type: application/json

{
  "name": "Treasury agent conversions above 5,000 USD",
  "description": "A person approves large conversions proposed by the treasury agent",
  "scope_ref": "enterprises/00000000-0000-4000-8000-000000000001",
  "operation_type": "conversion",
  "conditions": [
    {
      "kind": "initiator",
      "initiator_ref": "service-accounts/00000000-0000-4000-8000-000000000002"
    },
    {
      "kind": "amount_threshold",
      "amount_basis": "usd_equivalent",
      "operator": "gte",
      "threshold": {"value": "5000.00", "currency": "USD"}
    }
  ],
  "decision": {
    "kind": "require_approval",
    "reason": "agent_conversion_over_limit",
    "threshold": 1,
    "initiator_cannot_approve": true,
    "approver_role_ref": "roles/00000000-0000-4000-8000-000000000004"
  }
}
```

A rule is created as a `draft` and does nothing until it is activated with the
`etag` from the response:

```http
POST https://b2b2x-sandbox.youhodler.com/api/policy-rules/<rule_id>/activate
Authorization: Bearer <admin_access_token>
If-Match: <etag>
Idempotency-Key: rule-agent-conversions-001-activate
```

Add a second rule for a hard ceiling: the same conditions with `operator`
`gt`, a higher `threshold`, and a decision of `kind` `deny` with a `reason`.
Write the same pair for `internal_transfer` if the agent may start those. For
`withdrawal`, drop the amount condition: a `require_approval` rule with only
the `initiator` condition holds every withdrawal the agent starts, because a
withdrawal can go to any crypto address.

How the platform applies rules:

- **Most restrictive wins.** When several active rules match, `deny` beats
`require_approval`, which beats `allow`.
- **A rule that cannot be evaluated does not pass silently.** If a condition
needs a value the platform cannot compute at that moment (for example the USD
equivalent of the amount), a `deny` or `require_approval` rule that would
otherwise match asks for an approval instead.
- **Conditions per operation type.** `conversion`: `amount_threshold`,
`asset`, `asset_class`, `conversion_asset_class_pair`, `initiator`.
`internal_transfer`: `amount_threshold`, `asset`, `asset_class`,
`direction`, `initiator`. `withdrawal`: `amount_threshold`, `asset`,
`asset_class`, `initiator`. No condition matches on the withdrawal
destination, so a person approving each withdrawal is what keeps payouts on
known destinations.
- **A refusal is an error, not a status.** A deny rule answers the create
request with `422`, `code` `not_admissible`, `data.source` `policy` and
`data.reason` `POLICY_BREACH` (or `LIMIT_EXCEEDED`), and no operation
snapshot comes back.

The console shows rules under **Policies**. See
[Create policy rule](/api/reference/policies/policy-rules-create).

### When the agent's operation needs approval

The create request still succeeds, with `202`. The operation's `status` is
`pending_approval` and `approval_ref` holds `approval_id`, `reason_code` (the
rule's `reason`) and `expires_at`. The agent should record the approval id,
report it, and stop. Submitting again would only create a second held
operation, so keep one open proposal at a time.

The approval case, `GET /approvals/{approval_id}` (needs `approvals.read`),
shows its `status` (`pending`, `approved`, `rejected`, `cancelled` or
`expired`), `requirement_snapshot.required_human_approvals`,
`collected_human_approvals` and `initiated_by`, the agent. A case the policy
raises expires 24 hours after it opens unless someone decides.

**Who can decide.** A person, never a service account. They need
`approvals.decide` with a grant covering the operation's scope, the approver
role if the rule names one, and they cannot be the initiator when
`initiator_cannot_approve` is `true`.
`GET /approvals/{approval_id}/eligible-approvers` lists them. The decision is
`POST /approvals/{approval_id}/approve` or
`POST /approvals/{approval_id}/reject`, made in the console under **Approvals**
or by the person's own client. Both can ask for an MFA step-up
(`401 insufficient_user_authentication`). One rejection closes the case
whatever the quorum.

**What happens next.** On approval the operation continues and executes under
the agent's identity. The platform resolves the agent's rights again at that
moment, so a role revoked in the meantime is not used. On rejection or expiry
the operation ends `failed`, with `failure_reason` `APPROVAL_REJECTED` or
`APPROVAL_EXPIRED`. The events `operations.conversion.pending_approval.v1` and
`operations.conversion.approved.v1`, followed by `.settled.v1` or `.failed.v1`,
let the agent follow without polling. The same events exist for withdrawals
and internal transfers.

### Action tokens and human step-up

When a **person's** token submits a conversion, a withdrawal or an external
settlement conversion, the request also needs an `X-Action-Token` header. The
person's client gets the token from `POST /action-tokens` with
`{"action": "conversion.create", "command": <the same body>}`. The token is
bound to that person and that exact command, lasts five minutes and works once,
and issuing it can require an MFA step-up.

Service accounts are exempt and cannot get one: the request is refused, with
`401` from the MFA check or with `403`. So:

- An agent on its own service account sends no action token. The policy rule
is its brake.
- For "the agent drafts, a person confirms", let the agent prepare the exact
request body and have the person's session issue the action token for it and
submit it. The token proves the person approved those exact amounts, and the
operation is attributed to the person. See
[Issue action token](/api/reference/action-tokens/action-tokens-create).

## 3. What the agent reads

| Question | Call | Notes |
| --- | --- | --- |
| How much is there? | `GET /master-accounts/{master_account_id}/balances`, `GET /client-accounts/{client_account_id}/balances` | Plan with `available`; `held` is reserved for operations in flight. |
| What does it cost right now? | `GET /prices/indicative` | Non-binding. `account_ref` is required; the price is the one that account would get. |
| What fees apply? | `POST /fee-previews` | Non-binding; reserves nothing. |
| What would this conversion return? | `POST /conversions/preview` | `binding` is always `false`; check `execution_min_source_amount`. |
| Which pairs exist? | `GET /conversion-pairs` | Global catalog, not a per-account guarantee. |
| What happened? | `GET /conversions`, `GET /internal-transfers`, `GET /withdrawals`, `GET /deposits` | One status list for all families. |
| Where may money go? | `GET /withdrawal-destinations` | The registered destinations. The API does not limit the agent to them; an approval rule on its withdrawals does. |
| What changed? | `GET /events` | Or webhooks a person sets up; see [Events and webhooks](/guides/events-and-webhooks). |
| What waits for a person? | `GET /approvals` with `scope_ref` and `status=pending` | |
| What may I do? | `GET /me/capabilities` | Check it at start-up; refuse to run with rights from the list above. |

For example, the price of covering an 8,000 USD shortfall from pesos:

```http
GET https://b2b2x-sandbox.youhodler.com/api/prices/indicative?from_asset=ARS&to_asset=USD&amount_basis=to&to_amount=8000.00&account_ref=master-accounts/00000000-0000-4000-8000-000000000001
Authorization: Bearer <access_token>
```

`from_amount` in the answer is what it would cost. Then preview that amount
with `POST /conversions/preview` to see the fees; the request and response are
in [Smart treasury and international payments](/use-cases/treasury-and-international-payments).

## 4. What the agent does

Every write follows the same pattern: preview, choose an idempotency key,
write the key down, submit, follow the operation, report.

**Convert.**

```http
POST https://b2b2x-sandbox.youhodler.com/api/conversions
Authorization: Bearer <access_token>
Idempotency-Key: treasury-agent-7f3c2a10-5b1e-4c55-9a8e-2f1d0c3b4a59
Content-Type: application/json

{
  "account_ref": "master-accounts/00000000-0000-4000-8000-000000000001",
  "from_amount": {"value": "11764705.89", "currency": "ARS"},
  "to_currency": "USD"
}
```

**Move funds between your own accounts.**

```http
POST https://b2b2x-sandbox.youhodler.com/api/internal-transfers
Authorization: Bearer <access_token>
Idempotency-Key: treasury-agent-0b8d6e2c-31a4-4f7b-8c19-6a5e4d3c2b10
Content-Type: application/json

{
  "amount": {"value": "2500.00", "currency": "USD"},
  "source_ref": "master-accounts/00000000-0000-4000-8000-000000000001",
  "target_ref": "client-accounts/00000000-0000-4000-8000-000000000005"
}
```

**Pay a destination that is already registered.** The agent sends the
destination's id; it never sends bank details or an address.

```http
POST https://b2b2x-sandbox.youhodler.com/api/withdrawals
Authorization: Bearer <access_token>
Idempotency-Key: treasury-agent-c4a1e9f2-7d3b-4e0a-b5c6-1f2e3d4c5b6a
Content-Type: application/json

{
  "account_ref": "master-accounts/00000000-0000-4000-8000-000000000001",
  "amount": {"value": "1200.00", "currency": "USD"},
  "rail": "fiat",
  "withdrawal_destination_id": "00000000-0000-4000-8000-000000000006"
}
```

For a crypto payout the stored destination is `destination_id` with `rail`
`crypto`. `POST /withdrawals` also accepts a one-time inline `destination` for
crypto; an agent should never use it, and nothing on the platform stops it
from doing so except an approval rule on its withdrawals (step 2).

**Idempotency.** Use one key per decision, for example derived from the
agent's own decision id, and store it before sending. On a timeout, `429`,
`502` or `503`, send the same body with the same key: the platform returns the
first answer instead of creating a second operation. The answer is kept for 24
hours. A different body with a used key returns `409 idempotency_conflict`.
After an operation has failed, a new attempt needs a new key.

### Handle the outcome

| Answer | Meaning | What the agent does |
| --- | --- | --- |
| `202`, `status` `settled` | Executed. | Report the figures: `target_amount`, `applied_rate`, `fee_summary`. |
| `202`, `status` `requested`, `admissible` (conversion, internal transfer) or `executing` (withdrawal) | Accepted, still moving. | Follow the operation or its events until a final status. |
| `status` `executed` or `ledger_visible` | In the enum, but the platform does not set either today. | Treat it as not final: report it and keep reading. |
| `202`, `status` `pending_approval` | Held by a policy rule. | Record `approval_ref.approval_id`, report, stop. Do not resubmit. |
| `202`, `status` `pending_compliance` | Held for a compliance review. | Wait; the platform resumes it. |
| `status` `failed` or `cancelled` | Ended without moving the principal. | Read `failure_reason`; do not retry blindly. |
| `422` `not_admissible`, `data.source` `policy` | Refused by a deny rule. | Report it; a person must change the request or the rule. |
| `403` | Missing capability or account outside scope. | Stop and report; do not look for another way. |
| `401` `principal_revoked` | The service account was revoked or suspended. | Stop for good. |
| `429`, `502`, `503`, or no answer | Temporary. | Retry with the same key and backoff. |

Final statuses are `settled`, `partially_settled`, `failed` and `cancelled`.
Treat every other status as not final, as the
[transaction lifecycle](/guides/transaction-lifecycle#what-each-status-means)
does. See [Errors](/concepts/errors) for the error envelope and
[Rate limits](/concepts/rate-limits) for backoff.

## 5. Keep an audit trail

The platform records who did what. The agent records why.

- **On every operation**, `subject_attribution.authenticated_principal` is the
agent's service account (`kind` `service`, its id). The same block is on
every event the operation publishes.
- **On the approval case**, `initiated_by` is the agent and
`decision.decided_by` is the person who approved or rejected it.
- **In the audit log**,
`GET /user-action-audit-entries/search?enterprise_ref=<enterprise_ref>&authenticated_principal=service-accounts/<id>&occurred_from_utc=<from>&occurred_to_utc=<to>`
returns what the agent initiated (`audit.read`, a capability for your
compliance team, not for the agent). Entries about its operations have
`action_family` `financial_operation_audit` and the operation id in
`correlation_id`. The decisions on them are entries with `action_family`
`approval_decision`, where `attribution.initiated_by` is the agent,
`attribution.approved_by` the person, and `correlation_id` the same
operation id. The audit log records requests, holds, decisions, failures and
cancellations; settlement itself is in the operation and its events.
- **Exports** for auditors and accounting: `POST /user-action-audit-exports`
(`audit.create_export`) and `POST /operations-activity-exports`
(`operations_reports.create_export`), in `csv` or `json`.
- **The agent's own log**: for every decision, the inputs it saw, what it
proposed and why, the preview, the idempotency key and the operation id. Only
the agent knows its reasons; keep them next to the platform's record.

**Acting on behalf of a person.** If your integration exchanges a person's
identity token for an access token (see
[Identity](/concepts/identity#acting-on-behalf-of-a-human)), the platform
records that person as the actor; it does not keep the integration as a
separate actor. The person's rights apply, and their money movements need
their action token. Use this only when that person is really deciding. An
agent acting on its own uses its own service account, so the record says so.

## 6. Resources for agent builders

| Resource | What it is |
| --- | --- |
| [`/llms.txt`](/llms.txt) | Index of every docs page with a one-line description. |
| [`/llms-full.txt`](/llms-full.txt) | All docs pages in one file. |
| `/llms/<page path>.md` | Each page as Markdown, for example [this page](/llms/use-cases/ai-treasury-agent.md). |
| [`/openapi.json`](/openapi.json) | The contract. Each operation carries `x-required-capability`, so you can derive the capability list from the calls your agent makes. |
| [`/openapi-sandbox.json`](/openapi-sandbox.json) | Adds the sandbox-only simulation routes. |
| [Errors](/concepts/errors), [Rate limits](/concepts/rate-limits), [Idempotency](/concepts/idempotency-and-concurrency) | How to branch on failures, back off and retry safely. |

Give a model the documentation and the observation it must decide on, never
the credentials or the access token. Keep the API calls in your own code,
which applies the limits below to whatever the model returns.

## Safety checklist

- [ ] **Scoped credentials.** One service account per agent, a role with only
      the capabilities above, assigned at the narrowest scope. None of the
      "never grant" capabilities. The secret in a secret manager, with a
      bounded `client_secret_ttl_seconds`.
- [ ] **Approval thresholds on the platform.** A `require_approval` rule with
      an `initiator` condition for the agent and an amount threshold, and a
      `deny` rule above a hard ceiling, for each operation type it may start.
      Activated, and tested on sandbox.
- [ ] **Payouts held for a person.** `withdrawals.create` lets the agent pay
      any crypto address, because `POST /withdrawals` accepts an inline
      `destination`. Either do not grant it, or activate a `require_approval`
      rule with an `initiator` condition and no amount condition for all of
      the agent's withdrawals. The agent also pays only destinations a person
      registered (`destination_id`) and does not hold
      `withdrawal_destinations.create`, but that is its own discipline, not a
      platform control.
- [ ] **Dry run first.** Run with previews only (`POST /conversions/preview`,
      `POST /fee-previews`, `GET /prices/indicative`) until its proposals look
      right. They move nothing and need no capability.
- [ ] **Hard limits in the agent too.** Validate every proposal (currency,
      decimal string, per-operation maximum, reserve to keep) before any call,
      whatever produced it.
- [ ] **Idempotency key on every write**, stored before sending, reused on
      retry.
- [ ] **One open proposal at a time.** While an operation is
      `pending_approval`, propose nothing new.
- [ ] **Watch it.** Subscribe to the operation events, and review the audit
      search for the agent's service account regularly.
- [ ] **Kill switch.** A person revokes the service account with
      `POST /service-accounts/{service_account_id}/revoke` (needs
      `service_accounts.manage`). From the next request the agent's calls fail
      with `401 principal_revoked`, even with a token that has not expired.
      Then reject its pending approval cases. To pause rather than stop,
      revoke its role assignment with
      `POST /role-assignments/{role_assignment_id}/revoke`.

## Test it on sandbox

Sandbox-only Fund the account with a simulated deposit as in
[Sandbox testing](/guides/sandbox-testing), then:

1. Check that your pair exists for your account: `GET /conversion-pairs` and a
`POST /conversions/preview`. Adjust the agent's currencies if not.
2. Create the role, the service account and the policy rule above, and
activate the rule.
3. Run the agent in preview-only mode, then for real with an amount above the
threshold. The conversion stops at `pending_approval`.
4. Approve it in the console under **Approvals**, signed in as a person who
holds the approver role the rule names.
5. Revoke the service account and confirm the agent's next call answers
`401 principal_revoked`.

The [treasury-agent](/examples#treasury-agent) example does steps 3 to 5 for
you, and its mock mode shows the whole flow without credentials.

## Related

- [Smart treasury and international payments](/use-cases/treasury-and-international-payments):
the treasury calls in detail.
- [Example apps](/examples): treasury-agent and the others, each with a mock
mode.
- [Policies and approvals](/concepts/policies-and-approvals),
[Access](/concepts/access), [Identity](/concepts/identity).
- Reference: [Service accounts](/api/reference/service-accounts),
[Roles](/api/reference/roles), [Policies](/api/reference/policies),
[Approvals](/api/reference/approvals),
[Audit log](/api/reference/user-action-audit-entries).
