Implement a Spending Limit for Regulatory Compliance

intermediate agents 15 min

Set an agent's spending limit in MAWS, test it with preflight, and see exactly what does — and does not — enforce it.

What You Will Learn

  • ✓How to set an agent's spending limit (stored in the IdentityRegistry, enforced by MAWS).
  • ✓How to use policy preflight to test limits.
  • ✓What MAWS and the chain's PCL each do with a violation.

Prerequisites

Tools Needed

MCP Client
To keep an AI agent within a budget, set a spendingLimit on its IdentityRegistry record. MAWS enforces it before it signs anything; the chain does not read it, so it does not bind a transaction sent with the agent wallet's key outside MAWS.
1

1. Set the Policy

Use policy.set to establish a 100 OKRW limit per transaction.

LLM Tool Call

policy.set json
{
  "agentId": "<agent-id>",
  "spendingLimit": "100"
}
2

2. Test with Preflight

Before attempting a transfer, use policy.preflight to see if a 150 OKRW transfer would be allowed.

LLM Tool Call

policy.preflight json
{
  "agentId": "<agent-id>",
  "to": "0xRandomAddress",
  "amount": "150"
}
Note: The preflight returns policyCheck.allowed: false and canTransact: false, with the reason Amount 150 OKRW exceeds spending limit 100 OKRW.
3

3. Attempt the Transfer

If the agent ignores the preflight and calls transfer.send for 150 OKRW anyway, the MCP server will block it off-chain and return a POLICY_REJECTED ToolError. transfer.send checks the balance before the policy, so the agent must hold at least 150 OKRW to reach this error; with less, it returns INSUFFICIENT_BALANCE instead.

LLM Tool Call

transfer.send json
{
  "agentId": "<agent-id>",
  "to": "0xRandomAddress",
  "amount": "150"
}

Conclusion

MAWS now refuses any transfer above the limit before signing it. That is the whole of this limit's enforcement: no chain module reads spendingLimit. For a cap the chain itself enforces, store a TransferLimit value (a 32-byte uint256 in atokrw); the chain enforces it only where AGENT_OKRW_TRANSFER_LIMIT_POLICY is configured, and the testnet's global policy does not configure it — see pcl-template-agent-okrw-transfer-limit-policy.
ESC
Type to search