Rule recipes
Complete rules to paste into the rule editor and adapt to your agent. Start from a payment cap, a format check, a required order or a budget per run.
Each recipe is a complete rule, written for the payments agent used across these docs. Paste one into the rule editor as text, then change the tool, argument and numbers to fit your agent. Learn the rule language explains how they work.
Cap an argument
Blocks a payment over 10000.
@id("payment-cap")
@sentence("A payment of {amount} is over the 10000 limit")
block (
agent,
tool == "issue_payment"
)
when {
call.args.amount > 10000
};Allow only listed values
Blocks a payment in any currency not on the list.
@id("currency-allowed")
@sentence("Payments in {currency} are not allowed")
block (
agent,
tool == "issue_payment"
)
unless {
call.args.currency in ["USD", "EUR", "GBP"]
};Check an argument's format
Blocks a payment without an invoice id of the form INV- and six digits.
@id("invoice-id-format")
block (
agent,
tool == "issue_payment"
)
unless {
present(call.args.invoice_id)
&& matches(call.args.invoice_id, "^INV-[0-9]{6}$")
};Require one call before another
Blocks a payment unless the same payee was verified earlier in the run.
@id("verify-before-pay")
@sentence("{payee} was not verified earlier in this run")
block (
agent,
tool == "issue_payment"
)
unless {
verify_payee{ args.payee == call.args.payee }
};Allow one call per argument value
Blocks a second payment for the same invoice in the same session.
@id("one-payment-per-invoice")
@per("invoice_id")
block (
agent,
tool == "issue_payment"
)
when {
issue_payment{}
};Cap a total across the run
Blocks the payment that would take the run's total over 25000. Add @scope("session") to count the whole session.
@id("run-payment-total")
@sentence("This payment brings the run total to {run_total}, over 25000")
block (
agent,
tool == "issue_payment"
)
unless {
run_total = sum(issue_payment{}.args.amount, call.args.amount);
run_total <= 25000
};Flag calls past a run budget
Flags every call after the run's first 40, to any tool. The calls still run.
@id("run-call-budget")
flag (
agent,
tool
)
unless {
len(calls(*[status == "any"]{})) < 40
};Apply a rule to one agent
Gives the agent named payments a cap of 2000, while other agents keep any cap they have. Change payments to a name your agent is seen under, or the rule does not save.
@id("payments-agent-cap")
@sentence("The payments agent pays at most 2000, not {amount}")
block (
agent == "payments",
tool == "issue_payment"
)
when {
call.args.amount > 2000
};Set thresholds with bands
Lets a payment up to 1000 run, flags one up to 10000 and blocks anything larger.
@id("payment-bands")
bands (
agent,
tool == "issue_payment"
)
by {
call.args.amount
}
then {
<= 1000: allow,
<= 10000: flag,
else: block
};Next steps
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.
Rule language reference
Every part of the rule language on one page. Annotations, effects, head slots, clauses, reads, operators, functions, patterns and syntax limits.
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.
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.
Last updated on