Block your first tool call
Run a rule that caps payments, then watch the Amiril SDK block a tool call on your laptop. You need no account and no API key to try it.
At the end of this page, a rule stops a payment of 20000 before the tool runs. A short script stands in for a payments agent with an issue_payment tool, and nothing leaves your laptop.
Before you start
- The Amiril SDK needs Python 3.11 or later, or Node.js 24 or later. Node.js 24 runs a TypeScript file directly, with no build step.
- An empty folder to work in.
Install the SDK
pip install amirilSave the rule
Save this file in your folder as payment-cap.rules.json. It blocks any call to issue_payment unless the amount is above 0 and at most 10000.
{
"schema": "amiril.rules/1",
"ruleset_version": "quickstart-1",
"rules": [
{
"id": "payment-cap",
"version": "1",
"mode": "enforce",
"description": "A payment must be above 0 and at most 10000",
"target": { "tools": ["issue_payment"] },
"assert": { "and": [{ ">": [{ "arg": "amount" }, 0] }, { "<=": [{ "arg": "amount" }, 10000] }] },
"action": "block"
}
]
}You do not need to change it. JSON is the form the SDK runs, and a local file lets you try it without an account. In your own project you write the same rule as rule text in the web app, and Amiril turns it into this JSON for the SDK.
Save the agent script
Save this beside the rule. It starts the SDK with the rule file and asks for two payments, 500 and then 20000.
import amiril
from amiril import plain
# #region setup
amiril.init(rules_file="payment-cap.rules.json") # no API key, so nothing leaves your laptop
agent = plain.Agent("payments")
@agent.tool
def issue_payment(payee: str, amount: float) -> str:
"""Send a payment to a payee."""
return f"Paid {amount} to {payee}"
# #endregion setup
# #region run
with agent.run(session_id="laptop-1") as run:
run.turn()
print(issue_payment(payee="Acme", amount=500))
run.turn()
refused = issue_payment(payee="Acme", amount=20000) # the tool does not run
print(refused["message"]) # what the model reads in place of the result
# #endregion runagent.tool hands your tool function to the SDK, which checks each call before the function runs. If a rule blocks the call, you get back an object with a message instead of the tool's result. agent.run marks one run of the agent. run.turn() marks a turn, the point where a real agent's model would pick its next call. Rules that count calls or check their order use these marks.
Run it
python agent.pySee the result
Paid 500 to Acme
The call to issue_payment was not performed. Rule payment-cap blocked it: A payment must be above 0 and at most 10000 (amount 20000). Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed.The payment of 500 runs, but the payment of 20000 never reaches the tool. The script gets the message on the second line instead, built from the rule's description. In your own agent, the model reads this message in place of the tool's result. It tells the model not to retry and to tell the user the payment was not made.
To run your workspace's rules in place of the file, see how to connect the SDK to your workspace.
Next steps
Add Amiril to an agent without a framework
Check each tool call of an agent loop you wrote yourself against your rules, in Python or TypeScript, with the core SDK package and nothing else.
Check your agent's tool calls with the Amiril SDK
The Amiril SDK runs inside your agent and checks each tool call against your rules before the tool runs. Pick the guide for your framework and language.
Write your first rule
Start from a rule Amiril drafted for an issue, or from a blank rule. Save it, publish it in Shadow, then switch it to Enforce in one environment.
How rules work
A rule checks each tool call your agent makes and lets it run, flags it or blocks it. Rules run in your agent, and Shadow mode shows what one would do first.
Last updated on