Skip to main content
After you read this page, you can write a small rule document, and you know which page holds each part of the language.

What a rule document is

A rule document is one YAML text. It tells the Anafi engine what to do for one account: when to act, and what to pay, swap or send. Each account has at most one committed rule document at a time. A new commit replaces the full document. A document holds named rules. Each rule has one trigger and one or more actions:
  • The trigger says when the rule fires: on a schedule, at fixed instants, when a transfer arrives or leaves, or when a token price crosses a level.
  • The actions say what the engine does when the rule fires: send tokens, swap tokens, pay a bank account, or send an email.
The engine acts for the account through the adapter that the owner granted a permission to. See how Anafi works and Contracts overview.

A first complete document

This document pays 25 USDC every Friday at 09:00 in Berlin, and sends 20% of each incoming USDC payment of 100 USDC or more to a savings address.
This document is valid on polygon, xlayer and polygon-amoy, for both account kinds, safe_module and erc20_allow. Each of the three networks has USDC, and fees_method names an ERC-20 fee token, which an erc20_allow account needs.

The shape of a document

A document is a YAML mapping with at most four top-level keys. Each key is optional, but the document must have rules or agent_envelope. Every other top-level key is refused. The full field reference is on Document structure.

How a document reaches the engine

The document never goes on chain as text. Your app sends it encrypted to the engine, and the owner commits its salted hash on chain.
1

Stage

The SDK encrypts the salt and the YAML on the device to the key of the engine. The Anafi API relays the encrypted text. The engine opens it, runs every check on Validation, and answers with a signed attestation and a list of warnings. A document that fails a check gets a refusal and is not stored.
2

Commit

The owner signs one transaction that writes the commitment keccak256(salt ‖ yaml) on chain. The engine adopts the document when it sees the commit.
3

Fire

The engine fires the rules of the adopted document. Each payment goes through the adapter of the account.
The full flow, with each wallet prompt and each HTTP call, is on Flows overview. The SDK calls are on Documents.

Author with a coding agent

Each Anafi API host serves the full rule language as one Markdown page. Give the URL of your network to your coding agent: The route is GET /api/dsl/docs. It needs no sign-in and no key. The three pages are the same, except for these parts:
  • The first paragraph names the network.
  • The paragraph about tokens lists the tokens that the engine can move on that network.
  • Only the polygon-amoy page has the off_ramp example, because only that network has a bank payout rail.
Read every document that an agent writes before the owner signs the commit. The commit is the consent of the owner.

The reading principle

A rule must have one meaning for a person who reads it. The language helps you:
  • Every mapping accepts only its known keys. An unknown key, such as max_executions: 5, is refused. It does not silently do nothing.
  • An empty allowlist is refused, because [] looks like “nobody” but would mean “anybody”.
  • An amount always names its token. A bare "50%" or "100" is not an amount.
  • A token symbol is case-sensitive. usdc is refused.
Some choices stay open in the grammar. Make them in the direction that keeps the rule clear:
  • Use calendar for a repeated schedule. Use at_fixed_time only for instants that no calendar pattern describes.
  • Set timezone on each calendar trigger that names a time of day. The default is UTC.
  • Write start and expiry as absolute instants. Resolve “tomorrow” or “for one month” before you write the document.
  • Do not rename a rule that is in use. The rule name is part of its identity. See rule identity.

Pages in this section

Document structure

Top-level keys, global, rule keys, YAML scalar rules, size limits.

Triggers

periodic, calendar, at_fixed_time, incoming_tx, outgoing_tx, price_crossed.

Actions

send_one, send_batch, exchange, notify, off_ramp.

Values

Amounts, percentages, trigger.value, arithmetic, ranges, rounding.

Limits

Allowlists, rule bounds, and the on-chain caps of an erc20_allow account.

Validation

Every refusal and warning, and what validates but does not run.

Examples

Complete documents for real use cases.

Grammar reference

The full schema, the expression grammar, and every numeric limit in one place.