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.
A rule checks the tool calls your agent makes. By default it checks each call before the tool runs, then lets the call run, flags it or blocks it.
A payment cap
Say a payments agent should never pay more than 10000 in one call. This rule says so:
@id("payment-cap")
@sentence("A payment of {amount} is over the 10000 limit")
block (
agent,
tool == "issue_payment"
)
when {
call.args.amount > 10000
};When the model asks for a payment of 20000, the tool does not run. The model gets this text in place of the tool's result:
The call to issue_payment was not performed. Rule payment-cap blocked it: A payment of 20000 is over the 10000 limit. Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed.A payment of 500 runs as if the rule were not there.
What a rule can do
A rule's effect is the word before its parentheses. It decides what happens to a call the rule fires on.
| Effect | What happens to a call |
|---|---|
block | The call does not run, and the model is told why |
flag | The call runs and is marked for review |
bands | The rule reads a value such as the amount. Its size decides whether the call runs, is flagged or is blocked |
A call that no rule fires on runs as normal. A flag rule can also check a call after the tool returns, or once when the run ends. The rule language reference shows how.
Where rules run
The Amiril SDK wraps your agent's tools and checks each call inside your agent's process. Each running process fetches the published rules for the environment of its API key. How rules reach your agent says how and how often.
The rules quickstart runs a rule from a local file and needs no account.
Drafts and modes
Every save makes a new version of the rule, and a new version is a draft. Your agents only ever get the published version, so a draft changes nothing until you publish it.
Publishing sends the version to every environment. Each environment, such as Production, has its own agents and API keys. The rule has its own mode in each one, and a new rule starts in Shadow. The rule's page shows and sets the mode for the environment picked at the top of the app.
| Mode | What the SDK does with the rule |
|---|---|
| Off | Nothing. Agents in that environment do not get the rule |
| Shadow | Checks each call and records what the rule would have done. The call runs either way |
| Enforce | Acts on the decision. A blocked call does not run |
In Shadow, the rule's page counts the calls the rule would have fired on. Watch what it would catch shows where to read the counts.
Test a rule on past calls before you switch it to Enforce. Enforce needs the Team plan.
Where rules come from
You can write a rule yourself in the rule editor, as text or with the builder. Write your first rule walks through it. On the New rule page, Describe the rule takes a request in your own words and writes it in the rule language.
Amiril also drafts rules for you. An issue is a group of your agent's runs that share one problem. When a rule could stop an issue's runs, Amiril drafts one and offers it as a rule suggestion.
Next steps
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.
Learn the rule language
Build the rules of a payments agent in short examples, from one amount limit to rules that read earlier calls in the run or the session.
Test a rule on past calls
Replay a rule over the tool calls your agents already made and see which ones it would have fired on, before it blocks anything.
Review rule suggestions
Amiril drafts a rule for an issue and tests it on your past runs. Read the evidence it shows, then dismiss the suggestion or create the rule as a draft.
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.
Last updated on