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

Skip to Content
AMIRILDocs

SDK configuration

Every option of the Amiril SDK's init and every environment variable it reads, in Python and TypeScript, with its type, its default and what it does.

init starts the SDK once per process. Many options can also come from an environment variable, listed below. An init argument wins over its variable, and the variable wins over the default. An empty string counts as unset.

In TypeScript, init from @amiril/sdk/node reads the process's environment variables. The init from @amiril/sdk is for edge runtimes and reads no variables unless you pass them as environ.

Two names here are easy to confuse with an Amiril environment. environment is only a label for where the process runs, and your API key decides the Amiril environment. env is a set of your own tags for rules to read.

Environment variables

Several variables label your installation. An installation is one service at one deployed version, with its replicas counted as one. Installations, next to Data in the app's sidebar, lists them.

VariableOptionWhat it does
AMIRIL_API_KEYapi_key, apiKeyThe API key. With an endpoint, the SDK takes its rules from Amiril and sends its decisions there
AMIRIL_ENDPOINTendpointThe address the SDK fetches rules from and sends decisions to. In the app, open Data in the sidebar and select Set up a new installation to copy it. There is no default. A key without an endpoint makes no network request
AMIRIL_RULES_FILErules_file, rulesFileA rules file. Without a key, rules come only from this file or the rules option. With a key it is the last fallback, used when Amiril has sent no rules and none are cached
AMIRIL_ENVIRONMENTenvironmentA label for where this process runs, such as staging, shown as Environment on the installation's page
AMIRIL_SERVICEserviceThe service name the installation is listed under
AMIRIL_VERSIONversionThe deployed version, shown as Deploy version
AMIRIL_COMMITcommitThe commit this process was built from
AMIRIL_CACHE_DIRcache_dir, cacheDirWhere the last good rules and unsent decisions are kept on disk
AMIRIL_DURABLE_PATHdurableA SQLite file that keeps call history across restarts

Python init options

amiril.init(rules=None, **options) returns a handle with three methods.

  • flush() sends queued decisions now.
  • report() returns the mode, the rules in use and the agents and tools each adapter covers.
  • shutdown() sends what is queued and stops contacting Amiril.

init raises TypeError for an option it does not know. Without a key, init also raises when it cannot read the rules file. The interface types in the table, such as DecisionSink, are defined in amiril.seams.

OptionTypeDefaultWhat it does
rulesdict, path or BundleSourceNoneA rules document, or a path to one. Pass rules or rules_file, not both
rules_filepathAMIRIL_RULES_FILEA rules file
mode"enforce", "shadow", "off""enforce"enforce follows each rule's own mode. A rule starts in Shadow, so only a rule set to Enforce can block a call. shadow records what every rule would do and blocks nothing. off checks nothing and allows every call
api_keystrAMIRIL_API_KEYThe API key
endpointstrAMIRIL_ENDPOINTThe SDK endpoint. See AMIRIL_ENDPOINT
environmentstrAMIRIL_ENVIRONMENTA label for where this process runs. See AMIRIL_ENVIRONMENT
servicestrDetectedThe service name
versionstrDetectedThe deployed version
commitstrDetectedThe commit
cache_dirpathCache directoryWhere the last good rules and unsent decisions are kept
namesdict[str, str]{}Maps an agent's name in your framework to the display name of the registered agent it belongs to. Rules and decisions keep the framework's name
agent_versionstrNoneThe agent's version, which rules can read
envdict{}Your own tags in the run context, which rules can read
predicatesdict[str, Callable]NoneYour own functions, for a rules document that calls them by name. The document lists those names under predicates
toolsiterable of strNoneThe tools the agent should call. A call to any other tool gets unknown_tool_action
unknown_tool_action"allow", "flag", "block""flag"What a call to a tool missing from tools gets
sinkDecisionSink, callable, or a list of themNoneReceives every decision
decision_logpathNoneAppends every decision to a JSON Lines file
reporterRegistrationReporterThe built-in reporterReceives the agents and tools each adapter covers, which the installation's Coverage card lists. Without an API key the SDK keeps them in memory
durablepath or DurableStoreAMIRIL_DURABLE_PATHKeeps call history in a SQLite file across restarts
durable_retention_msint604800000 (7 days)How long the file keeps a run no process has touched
history_max_recordsint20000How many calls history keeps at most
history_run_idle_msint3600000 (1 hour)A run idle this long is closed
history_session_idle_msint86400000 (24 hours)A session idle this long is closed
history_max_result_bytesint65536A tool result larger than this is cut short in history
handle_sigtermboolTrueOn SIGTERM, sends or saves queued decisions, then lets SIGTERM end the process as it would without the SDK. Only on the main thread, and only when no other handler is set
redactcallableNoneCalled with a copy of each object before it leaves your process, as a dict. That is a decision record, a coverage report or the attributes path_c writes. Return the dict to send, or None to send nothing. If it changes an id such as run_id or rule, the SDK drops that object
path_cboolFalseWrites each decision that is not an allow onto your active OpenTelemetry span, so your own traces show it
annotate_allowsboolFalseWith path_c, also writes amiril.decision = "allow" on allowed calls
startup_wait_msint2000How long the first call waits for Amiril's first answer. After that it uses the cached rules or the rules file
queue_capacityint10000How many decisions wait in memory at most. A full queue drops the oldest
spool_max_bytesint52428800 (50 MiB)How many bytes of unsent decisions are kept on disk at most
shutdown_budget_msint2000How long shutdown spends sending queued decisions
clockcallabletime.timeFor tests
timingTimingThe SDK's own timingsFor tests

TypeScript init options

init(options) from @amiril/sdk/node returns the same handle as in Python, with flush(), shutdown() and report(). init throws TypeError for an option it does not know. The types in the table, such as DecisionSink and Platform, are exported from @amiril/sdk.

OptionTypeDefaultWhat it does
rulesobject or BundleSourcenullA rules document. On an edge runtime, this is how rules arrive without a key
rulesFilestringAMIRIL_RULES_FILEA rules file
mode"enforce", "shadow", "off""enforce"enforce follows each rule's own mode. A rule starts in Shadow, so only a rule set to Enforce can block a call. shadow records what every rule would do and blocks nothing. off checks nothing and allows every call
apiKeystringAMIRIL_API_KEYThe API key
endpointstringAMIRIL_ENDPOINTThe SDK endpoint. See AMIRIL_ENDPOINT
environmentstringAMIRIL_ENVIRONMENTA label for where this process runs. See AMIRIL_ENVIRONMENT
servicestringDetectedThe service name
versionstringDetectedThe deployed version
commitstringDetectedThe commit
cacheDirstringCache directoryWhere the last good rules and unsent decisions are kept
namesRecord<string, string>{}Maps an agent's name in your framework to the display name of the registered agent it belongs to. Rules and decisions keep the framework's name
agentVersionstringnullThe agent's version, which rules can read
envRecord<string, unknown>{}Your own tags in the run context, which rules can read
predicatesRecord<string, PredicateFunction> or a MapnullYour own functions, for a rules document that calls them by name. The document lists those names under predicates
toolsstring[]nullThe tools the agent should call. A call to any other tool gets unknownToolAction
unknownToolAction"allow", "flag", "block""flag"What a call to a tool missing from tools gets
sinkDecisionSink or an array of themnullReceives every decision
reporterRegistrationReporterThe built-in reporterReceives the agents and tools each adapter covers, which the installation's Coverage card lists. Without an API key the SDK keeps them in memory
durablestring or DurableStoreAMIRIL_DURABLE_PATHKeeps call history in a SQLite file across restarts
historyPartial<HistoryLimits>As in PythonThe history_* limits of the Python table as maxRecords, runIdleMs, sessionIdleMs and maxResultBytes
redactfunctionnullCalled with a copy of each object before it leaves your process. That is a decision record, a coverage report or the attributes pathC writes. Return the object to send, or null to send nothing. If it changes an id such as run_id or rule, the SDK drops that object
pathCbooleanfalseWrites each decision that is not an allow onto your active OpenTelemetry span, so your own traces show it
annotateAllowsbooleanfalseWith pathC, also writes amiril.decision = "allow" on allowed calls
otelthe trace API of @opentelemetry/apiThe global one an OpenTelemetry SDK registersThe OpenTelemetry API pathC writes through. Without one, pathC writes nothing
startupWaitMsnumber2000How long the first call waits for Amiril's first answer. After that it uses the cached rules or the rules file
queueCapacitynumber10000How many decisions wait in memory at most. A full queue drops the oldest
spoolMaxBytesnumber52428800 (50 MiB)How many bytes of unsent decisions are kept on disk at most
shutdownBudgetMsnumber2000How long shutdown spends sending queued decisions
environRecord<string, string> or a functionThe process environmentThe environment variables to read
platformPlatformNode's, from @amiril/sdk/nodeThe environment variables, filesystem, host identity and fetch the SDK uses. Pass your own only for a runtime that is not Node
log(message: string) => voidconsole.warnWhere the SDK writes its log lines
clock, timers, timingFor tests

TypeScript has no decision_log. Pass a sink to keep every decision yourself.

A SQLite file opened through durable keeps a run no process has touched for 7 days. For another period, pass new SqliteStore(path, { retentionMs }) from @amiril/sdk/node.

Service name and version

Without the service option, the SDK takes the name and the version from the first row below that has a name. The version comes from that same row, so a row without one leaves the version empty.

SourceNameVersion
AmirilAMIRIL_SERVICEAMIRIL_VERSION
OpenTelemetryOTEL_SERVICE_NAMEservice.version in OTEL_RESOURCE_ATTRIBUTES
Cloud RunK_SERVICEK_REVISION
AWS LambdaAWS_LAMBDA_FUNCTION_NAMEAWS_LAMBDA_FUNCTION_VERSION
Your projectThe name in the nearest pyproject.toml (Python) or package.json (TypeScript)The version beside it
The folderThe name of the folder your started script is inNone
The hostThe host nameNone

The SDK looks for the project file in the folder of the script you started, then in each folder above it. Services in different projects get different names this way. Services in one project share its name and become one installation, so give each its own AMIRIL_SERVICE.

To change the name people see for an installation that is already listed, open it on the Installations page and select Rename. The SDK keeps reporting its own name, and the new one shows only in Amiril.

The commit comes from commit, then AMIRIL_COMMIT, then vcs.ref.head.revision in OTEL_RESOURCE_ATTRIBUTES.

Cache directory

Without cache_dir or AMIRIL_CACHE_DIR, the cache directory is $XDG_CACHE_HOME/amiril. Without XDG_CACHE_HOME it is amiril-<uid> in the system's temporary directory.

Call history

A rule can read earlier calls in the same run or session, such as how many times issue_payment ran. The SDK keeps those calls in memory as its call history, so a restart forgets them. Set durable or AMIRIL_DURABLE_PATH when such a rule must keep working after a restart. The history_* options bound how much history the SDK keeps.

Next steps

Last updated on