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

Skip to Content
AMIRILDocs

How rules reach your agent

The SDK keeps your published rules in the agent's process and checks each tool call there. It keeps checking when Amiril is unreachable or the agent restarts.

You write and publish rules in Amiril. The SDK keeps a copy inside your agent's process and checks each tool call against that copy, so a check makes no network request of its own.

Change a rule without a redeploy

Your payments agent runs in Production with payment-cap in Enforce. The rule blocks payments above 10000. You lower the cap to 5000 and publish the new version. Within about a minute, every running process with a Production API key blocks payments above 5000.

To watch the change arrive, open your service on the Installations page. Rules in use shows the rules version its processes run.

Sync in the background

When the SDK starts, it connects to Amiril and gets the rules published for its key's environment. After that it asks for changes about once a minute. It only ever gets published versions, so a draft stays in Amiril.

The SDK validates a new set of rules before it uses any of them. A set that passes replaces the old one in a single step, so a run sees the new rules from its next call and never a mix. A set that fails validation is refused, and the SDK keeps the rules it has. The Refused rules versions table on your service's page gives the reason.

The SDK also sends Amiril what it decided for each call, in batches. The rule's page counts what it blocked, flagged and allowed.

The first call after start

Connecting does not delay your agent's start. Only the first tool call waits, for up to 2 seconds, for Amiril's answer. If none comes, the call goes ahead with the rules an earlier process saved to disk. With no rules at all, the call runs and is recorded.

While Amiril is unreachable

The SDK keeps checking calls with the last rules it received. It also saves them in its cache directory, which AMIRIL_CACHE_DIR sets. If the agent restarts while Amiril is unreachable, the SDK loads that copy and goes on enforcing it. In a container, put the cache directory on a volume that outlives the container. Decisions wait in memory and on disk, and the SDK sends them once Amiril answers again. The Rule sync card on your service's page shows how many syncs in a row have failed.

Calls the SDK cannot check

A bug inside the SDK can stop it from checking a call. The call then runs, unless a rule that covers it says otherwise. Each rule has the setting If the SDK cannot check a call, under Roll-out in the rule editor:

  • Let the call run is the default. The failure is recorded and the call goes ahead.
  • Stop the call blocks a call the rule covers whenever the SDK cannot check it.

The setting applies only while the rule is in Enforce.

Run history across restarts

Some rules read earlier calls in the run or the session, such as one that allows a single payment per invoice. By default the SDK keeps that history in memory, so a restart forgets it.

Give the SDK a file to keep its history in, on a disk that outlives the process:

export AMIRIL_DURABLE_PATH=/var/lib/payments-agent/amiril-history.sqlite

When your framework resumes a run from its own checkpoint, the SDK loads the run's history from the file first. A call it blocked before the restart is blocked again. Rules that read only the call itself need no file.

Give each running process its own file. In TypeScript, the file works only with the init from @amiril/sdk/node, which the guides use.

Next steps

Last updated on