Spending caps, allowlists, and human-in-the-loop policy engine.
Put guardrails around what autonomous agents can spend and call — before money moves on chain or a paid API runs. Budgets are enforced in the kit; signing, allowlists, and approvals stay where custody belongs: your app and your users.
Autonomous agents need boundaries. The Trust Layer is the control plane for what is this agent allowed to do with money and external services? In Web3 Agent Kit, trust is not a single switch — it is a set of enforceable checks and composable patterns. The kit enforces spend policy on fixed-price tools (e.g. get_token_price at $0.001); your application enforces recipient allowlists, transfer approval, and policy on variable paid_fetch calls.
Built-in controls
06
Per-agent spend policy.
Daily or monthly USD budgets on kit-priced MCP tools. Evaluated before x402 payment is requested or verified.
Spend ledger.
Rolling totals per agent in agent_spend_ledger so caps are real, not cosmetic. Idempotent requestKey on retries.
Invocation guardrails.
HTTPS-only paid_fetch, optional host allowlist, discovery price filters for third-party APIs before payment.
Human-in-the-loop by design.
Unsigned transfers and payment-required flows pause until a wallet or your UI approves. Natural pause points, not mystery failures.
Deny with data.
Budget exceeded returns a spend denial with limitUsdMicros, spentUsdMicros, remainingUsdMicros for agents and UIs to recover.
Custody stays with you.
Kit enforces fixed-price tool budgets. Your app enforces transfer allowlists and variable paid_fetch policy. No private keys in the service.
Cap kit spend. Gate external calls. Keep humans in the loop.
03Policy
Spend policy is built in
Configure per agent via PATCH /agents/:id/spend-policy. Stored on the agent as metadata.spendPolicy. Evaluated before every paid kit tool runs — before x402 payment is requested or verified.
Per-agent fields
enabled
Turn policy on or off for this agent
budgetUsd
Maximum spend in USD for the period (e.g. "5.00")
period
daily or monthly (UTC windows)
hardBlock
When false, over-budget calls are logged but allowed (advisory); when true (default), calls are denied
Global operator controls
SPEND_POLICY_ENABLED
Master switch (default false); must be true for any per-agent policy to enforce
SPEND_POLICY_DRY_RUN
Log would-be denials but allow the call (staging / rollout without blocking users)
When a call exceeds budget, MCP returns a Spend Policy Denied error with structured data:
reason — budget_exceeded or invalid_policy_config
message — Human-readable explanation for UI and alerts
limitUsdMicros, spentUsdMicros, remainingUsdMicros — Structured limits for agents and dashboards
After successful paid kit tool settlement, spend is recorded in agent_spend_ledger so the next call sees accurate period totals.
04Scope
What spend policy covers (and what it does not)
Covered — kit-priced MCP tools
Today: get_token_price ($0.001 per call). Any tool with a fixed price in its descriptor goes through: evaluate budget → payment required → verify → execute → settle → ledger entry.
Not covered — variable third-party APIs
paid_fetch uses whatever price the external x402 resource demands. Spend policy does not cap those amounts. Use Discovery Layer filters (maxUsdPrice, network, asset) and your own app rules before the agent calls paid_fetch.
Not covered — on-chain transfers
transfer builds unsigned transactions only. The kit does not sign, broadcast, or enforce recipient allowlists or transfer spend limits. Response includes policy.allowlistEnforced: false — custody and approval stay in the wallet or your signing service.
05Allowlists
Allowlists and access control
Host allowlist (paid_fetch)
Set PAID_FETCH_HOST_ALLOWLIST to comma-separated hostnames. When configured, paid_fetch may only call those HTTPS hosts — blocking drive-by URLs from prompts or tool hallucinations. Private and local hosts are always blocked.
Discovery filters (operational allowlisting)
discover_services supports maxUsdPrice, payTo, network, asset, and scheme so agents only see catalog entries that match your platform's economic and network rules — before any payment is attempted.
Recipient / merchant allowlists (your app)
Transfer recipients and high-value payouts are not hard-coded in the kit. Recommended pattern: your backend or UI validates to addresses against an allowlist before signing the unsigned tx returned by transfer.
API key & tenant scope (always on)
REST and MCP validate credentials per app and agent. Per-agent API keys are 1:1 with agent rows; application keys require agent_id scoping for multi-customer platforms. Baseline trust — isolation before policy.
06HITL
Human-in-the-loop
The kit does not replace your approval UI — it creates natural pause points.
Unsigned transfers
transfer
transfer returns intent, unsigned transaction, and preflight suggestions. Nothing hits chain until your user or signing service approves — perfect for review amount and recipient flows in mobile or dashboard.
Payment required
payment required
Paid kit tools and paid_fetch first return payment requirements. The host must obtain a signature (wallet, smart account, or delegated signer) before retrying with paymentPayload. Insert confirmation modals, step-up auth, or parent approval between probe and pay.
Spend denial
spend denied
When budget is exceeded, the agent receives a clear denial — not a silent failure. Surface remaining budget in your UI and offer request higher limit or human override workflows outside MCP.
Advisory mode
dry-run
Roll out policies in observe-only mode: SPEND_POLICY_DRY_RUN=true globally or hardBlock: false per agent. Log violations, alert operators, train models — then flip to hard block when ready.
07Flow
Spend policy flow
1
Enable globally
Set SPEND_POLICY_ENABLED=true in your deployment.
2
Set per-agent budget
PATCH /agents/:id/spend-policy with enabled, budgetUsd, period, and optional hardBlock.
3
Agent calls a paid kit tool
On tools/call (e.g. get_token_price), the router: (1) loads metadata.spendPolicy for the session agent, (2) sums agent_spend_ledger for the current daily or monthly UTC window, (3) compares projected spend (spent + tool price) to budgetUsd, (4) denies the request or continues to x402 payment flow.
4
After successful settlement
Ledger records the spend in agent_spend_ledger (tool name, amount, request key, settled timestamp). Duplicate request keys are skipped idempotently. Remaining budget updates for the next call in the same period.
08Design
Design principles
Deny with data, not mystery
Policy failures return machine-readable limits and remaining budget so agents and UIs can explain why and recover gracefully.
Enforce where price is known
Fixed kit tool prices are enforceable pre-payment. Variable third-party prices are steered via discovery and app policy — not guessed in the router.
Custody stays out of the kit
No signing keys in the service. Trust for transfers and large payments is composable: kit prepares, you approve and sign.
Operator + per-agent knobs
Global flag for rollout; per-agent budgets for tenant/customer segmentation; dry-run and advisory hardBlock for safe adoption.
Idempotent ledger
requestKey deduplication prevents double-counting when clients retry payments.
MCP trust-related responses: Payment Required — approve or sign, then retry with paymentPayload. Spend Policy Denied — see error.data.spendPolicy for limits and remaining budget.