Implement a Spending Limit for Regulatory Compliance

intermediate agents 15 min

Learn how to configure an agent's on-chain policy to enforce a strict spending limit, ensuring autonomous actions remain compliant.

What You Will Learn

  • How to set an on-chain spending limit.
  • How to use policy preflight to test limits.
  • How the two-layer policy model handles violations.

Prerequisites

  • An ACTIVE agent with at least 2,000,000 OKRW.

Tools Needed

MCP Client
To prevent an AI agent from draining funds or violating regulatory volume limits, you can set a hard spendingLimit on its IdentityRegistry record.
1

1. Set the Policy

Use policy.set to establish a 1,000,000 OKRW limit per transaction.
policy.set json
{
  "agentId": "<agent-id>",
  "spendingLimit": "1000000"
}
2

2. Test with Preflight

Before attempting a transfer, use policy.preflight to see if a 1,500,000 OKRW transfer would be allowed.
policy.preflight json
{
  "agentId": "<agent-id>",
  "to": "0xRandomAddress",
  "amount": "1500000"
}
Note: The preflight will return `allowed: false` with a reason indicating the amount exceeds the 1,000,000 OKRW limit.
3

3. Attempt the Transfer

If the agent ignores the preflight and calls transfer.send for 1,500,000 OKRW anyway, the MCP server will block it off-chain and return a POLICY_REJECTED ToolError.
transfer.send json
{
  "agentId": "<agent-id>",
  "to": "0xRandomAddress",
  "amount": "1500000"
}

Conclusion

Setting the policy on-chain guarantees the agent cannot exceed its bounds — the same dual-track enforcement (off-chain MAWS preflight + on-chain PCL) catches it regardless of which path the transaction takes.
Source: maroo-agents
ESC
Type to search