Need more detail? Connect your coding agent to the full docs.

Skip to Content
AMIRILDocs

Rule language reference

Every part of the rule language on one page. Annotations, effects, head slots, clauses, reads, operators, functions, patterns and syntax limits.

Look up any part of the rule language here. Learn the rule language teaches the same parts with examples. A rule is written in this order:

@annotation("value")
effect (head)
when or unless { condition };

A rule may also put a guard, when { guard }, before that last line. See clauses.

Annotations

A rule takes each annotation at most once, before its effect.

AnnotationMeaning
@id("payment-cap")The rule's id. Lower-case letters, digits and single hyphens, up to 64 characters. Fixed once the rule is published
@sentence("...")The sentence when the rule fires. {name} fills in an argument the rule reads or a named value
@sentence_pass("...")The sentence when the call passes
@scope("session")Earlier calls come from every run in the session. Without it, from this run
@per("invoice_id")Earlier calls with the same invoice_id, from any run in the session

A rule takes @scope or @per, not both.

Effects

EffectWhat happens to the call
blockIt does not run. The model gets the rule's sentence in place of the tool's result
flagIt runs, and is flagged for review
bandsThe rule measures the value in by { }. Each band in then { } acts with allow, flag or block

A bands rule ends with then { <= 1000: allow, <= 10000: flag, else: block }. The numbers rise from the first band, and else takes the rest.

Head slots

The head comes in parentheses after the effect. Its slots pick the agents, the tools and the moment a rule checks.

SlotCovers
agentEvery agent. Leaving the slot out means the same
agent == "payments"One agent, by a name Amiril already has for it
agent in ["a", "b"]Several agents
toolEvery tool
tool == "issue_payment"One tool
tool in ["a", "b"]Several tools
at == "before_call"Checked before the tool runs. Leaving the slot out means the same
at == "after_call"Checked after the tool returns. flag only
at == "run_end"Checked once when the run ends. flag only. No tool slot, and no reads of call.args or call.result

Clauses

ClauseThe rule fires when
when { C }C is true
unless { C }C is false
when { G } before a second clauseG is true and the second clause fires. A call where G is false is not checked at all

A named value such as payee = call.args.payee; goes first inside the last clause's braces, before the condition. The lines below it can use it.

Values a rule can read

ReadValue
call.args.amountAn argument of the call being checked. call.args.payee.iban reads a nested field
call.tool_idThe call's tool
call.statuspending before the tool runs. After it returns, ok or error
call.result.xA field of what the tool returned, in a rule checked after the call
prev.tool_id, prev.status, prev.args.xThe call just before this one
ctx.agent_id, ctx.agent_versionThe calling agent and its version
ctx.run_id, ctx.session_idThe run and the session of the call
ctx.env.regionA tag you pass to the SDK's init with env. See SDK configuration
ctx.nowThe time of the call, in seconds since 1970
nameA named value defined above

Operators

OperatorMeaning
|| && !Or, and, not
== != < <= > >=Comparisons. They do not chain, so write 0 < x && x < 10
inIn a list such as ["USD", "EUR"]. Lists take fixed values only
+ - * /Arithmetic
( )Grouping

Functions

FunctionReturns
present(x)Whether x has a value. False when it is missing or null
len(x)The length of a string or list
abs(x)The absolute value
min(a, b, ...), max(a, b, ...)The smallest or largest value
matches(x, "^INV-[0-9]{6}$")Whether the whole of x matches the regular expression
starts_with(x, "INV-")Whether string x starts with the second string
contains(x, "refund")Whether string x has the second string anywhere in it
hour_utc(x)The UTC hour, 0 to 23, of a time such as ctx.now
weekday(t, "Europe/London")The day of the week of time t in that time zone, from "Mon" to "Sun"
hour(t, "Europe/London")The hour, 0 to 23, of time t in that time zone
date(t, "Europe/London")The date of time t in that time zone, as "2026-12-03"
time(t, "Europe/London")Time t in seconds since 1970, like ctx.now. t may be a string such as "2026-12-03T17:30", and one without an offset is read in that time zone
minutes(n), hours(n), days(n)That many minutes, hours or days, counted in seconds. ctx.now + hours(2) is two hours from now
all(list, cond), any(list, cond)Whether every item, or any item, meets cond. it is the item
is_number(x)Whether x is a number
is_string(x)Whether x is a string
is_boolean(x)Whether x is true or false
is_null(x)Whether x is null
is_list(x)Whether x is a list
is_object(x)Whether x is an object

An argument the call leaves out or sends as null never makes a condition true. So when { call.args.fee > 20 } lets that call run, and unless { call.args.fee <= 20 } blocks it. Only present(), the is_ functions, == and != test for null.

weekday(), hour(), date() and time() need SDK 0.1.0 or later in either language. An older SDK skips a rule that uses them. If the rule is in Enforce and its If the SDK cannot check a call setting is Stop the call, the older SDK blocks every call the rule checks.

Patterns

A pattern matches earlier calls. It names a tool, then optional slots in square brackets and a condition in braces. Inside the braces, a bare field such as args.payee or result.registered reads the earlier call. call. reads the current call.

Tools in a pattern

PatternMatches earlier calls
verify_payee{}To verify_payee
verify_payee{ args.payee == call.args.payee }To verify_payee that meet the condition
verify_payee|lookup_payee{}To either tool
*{}To any tool
"Verify Payee"{}To a tool whose name is not a bare word

Pattern slots

A slot goes in square brackets after the tool, as in issue_payment[status == "error"]{}. Without a status slot, a pattern matches only calls that succeeded.

SlotMatches
[status == "error"]Only calls that failed
[status == "blocked"]Only calls a rule blocked
[status == "any"]Calls whatever their status
[same == "invoice_id"]Only calls with the same invoice_id as the current call

Order, counts, totals and lookups

FormValue
T{}Whether a matching call happened
A{} -> B{}Whether every call matching A has a later call matching B
latest(T{}).result.xA field of the most recent match. first(T{}) takes the earliest
every(T{}).args.xThat field of every match, as a list
calls(T{})The matches, for len, all and any
count(T{})How many calls match
sum(T{}.args.amount)The total of a field. Extra arguments, as in sum(T{}.args.amount, call.args.amount), are added to it
min(T{}.f), max(T{}.f), count_distinct(T{}.f)The smallest, the largest, and the number of different values

Syntax and limits

  • Strings take double quotes.
  • Comments are not supported.
  • A rule is at most 8,000 characters.
  • Amiril saves the rule in one layout, so your text may come back spaced differently.

Next steps

Last updated on