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

Skip to Content
AMIRILDocs
/

Rules

The Rules routes of Amiril's HTTP API that an OAuth access token can call, with their parameters, request bodies and responses.

List rules

GET
/api/rules

Newest first, archived rules only with archived=include, each with its mode in the session's environment and in every live environment, with the bundle installations in the session's environment sync now.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Query Parameters

archived?"include"
Value in"include"

Response Body

The workspace's rules

application/json
  1. response
rules*array<>
bundle*|

The bundle installations in the session's environment sync now; null when nothing was ever published there

Example Request
curl -X GET 'https://api.amiril.ai/api/rules'
Example Response200
{  "rules": [    {      "id": "string",      "name": "string",      "description": "string",      "mode": "off",      "modes": [        {          "environment": "string",          "mode": "off"        }      ],      "failMode": "open",      "appliesTo": {        "agents": [          "string"        ],        "tools": [          "string"        ]      },      "latestVersion": 0,      "publishedVersion": 0,      "publishedAt": "string",      "createdBy": "string",      "createdAt": "string",      "updatedAt": "string",      "archivedAt": "string",      "warnings": [        {          "code": "agent_unresolved",          "agent": "string",          "message": "string"        }      ],      "liveSince": {        "bundleVersion": "string",        "at": "string"      },      "shown": {        "version": 0,        "rule": {          "property1": null,          "property2": null        },        "text": "string"      }    }  ],  "bundle": {    "version": "string",    "etag": "string"  }}

Create a rule

POST
/api/rules

Stores the rule as version 1, a draft: installations do not see it until it is published. text spells the whole rule; rule carries what the text does not spell. Its id is the one given, else the text's @id, else a slug of its name made unique in the workspace. A mode given applies in the session's environment; every other environment starts in shadow. Saved fromDraft, the draft is linked to the rule, which answers the suggestion it made, and the first version's change note says where it came from.

Needs a full access token. A read-only token is refused.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Request Body

application/json
  1. body
id?string

The text's @id when omitted, else derived from the name

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64
name*string
Length1 <= length <= 200
description?|null
rule?

Defaults to {} when text is given; one of rule and text is required

text?string

The whole rule in the rule language (grammar in GET /api/schema): its id, the agents and tools its head names, when it is checked, its action, scope, sentences and condition. Replaces every key of rule the text spells; rule then carries only what the text does not spell: description, if_missing, on_error

Lengthlength <= 8000
mode?string

The mode in the session's environment; defaults to shadow, which every other environment starts in

Value in"off""shadow""enforce"
failMode?string

Defaults to open

Value in"open""closed"
changeNote?|null
fromDraft?string

The rule draft it was saved from, so the draft's issue shows the rule once it is published

Match^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
Formatuuid

Response Body

The new rule

application/json
  1. response
rule*
versions*array<>

Newest first

document*

The latest version as the bundle would carry it with the current settings, agents as the names they send

agents*

Since when the rule has had the agents it has now. Counts and backtests from before sinceVersion were for other agents

Example Request
curl -X POST 'https://api.amiril.ai/api/rules' \  -H 'Content-Type: application/json' \  -d '{  "name": "string"}'
Example Response
{  "rule": {    "id": "string",    "name": "string",    "description": "string",    "mode": "off",    "modes": [      {        "environment": "string",        "mode": "off"      }    ],    "failMode": "open",    "appliesTo": {      "agents": [        "string"      ],      "tools": [        "string"      ]    },    "latestVersion": 0,    "publishedVersion": 0,    "publishedAt": "string",    "createdBy": "string",    "createdAt": "string",    "updatedAt": "string",    "archivedAt": "string",    "warnings": [      {        "code": "agent_unresolved",        "agent": "string",        "message": "string"      }    ],    "liveSince": {      "bundleVersion": "string",      "at": "string"    },    "shown": {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string"    }  },  "versions": [    {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string",      "author": "string",      "changeNote": "string",      "createdAt": "string",      "publishedAt": "string"    }  ],  "document": {    "property1": null,    "property2": null  },  "agents": {    "sinceVersion": 0,    "gained": {      "names": [        "string"      ],      "everyOther": true    }  }}

Check a rule

POST
/api/rules/validate

Loads the rule with the given settings through the SDK's own engine and returns every problem it reports, with the rule as the bundle would carry it.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Request Body

application/json
  1. body
rule*

One rule of an amiril.rules/1 document, head (target, agents) included. An id names the rule and is not stored; version, mode and fail_mode come from the rule's settings and are removed if present

text?string

The whole rule in the rule language (grammar in GET /api/schema): its id, the agents and tools its head names, when it is checked, its action, scope, sentences and condition. Replaces every key of rule the text spells; rule then carries only what the text does not spell: description, if_missing, on_error

Lengthlength <= 8000
mode?string

off: not evaluated. shadow: evaluated and recorded, never acts. enforce: its decision takes effect

Value in"off""shadow""enforce"
failMode?string

What happens to a call the rule targets when the SDK faults before deciding: closed stops it. Applies only while the rule enforces

Value in"open""closed"

Response Body

Problems, empty when the rule loads

application/json
  1. response
problems*array<>

Empty when the SDK loads the rule

warnings*array<>

What loads but may not do what was meant; never stops a save

document*

The rule as the bundle would carry it

Example Request
curl -X POST 'https://api.amiril.ai/api/rules/validate' \  -H 'Content-Type: application/json' \  -d '{  "rule": {    "property1": null,    "property2": null  }}'
Example Response
{  "problems": [    {      "path": "string",      "code": "string",      "message": "string"    }  ],  "warnings": [    {      "path": "string",      "code": "matches_partial_anchor",      "message": "string"    }  ],  "document": {    "property1": null,    "property2": null  }}
POST
/api/rules/preview

The sentences the SDK's engine renders for the rule: the decision sentence, the text the model is handed when the call is stopped, and what a reviewer reads. With a sample call, the decision the rule takes on it.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Request Body

application/json
  1. body
rule*

One rule of an amiril.rules/1 document, head (target, agents) included. An id names the rule and is not stored; version, mode and fail_mode come from the rule's settings and are removed if present

text?string

The whole rule in the rule language (grammar in GET /api/schema): its id, the agents and tools its head names, when it is checked, its action, scope, sentences and condition. Replaces every key of rule the text spells; rule then carries only what the text does not spell: description, if_missing, on_error

Lengthlength <= 8000
mode?string

off: not evaluated. shadow: evaluated and recorded, never acts. enforce: its decision takes effect

Value in"off""shadow""enforce"
failMode?string

What happens to a call the rule targets when the SDK faults before deciding: closed stops it. Applies only while the rule enforces

Value in"open""closed"
ruleId?string

The rule being edited, so the model's text names it as installations will

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64
call?|

A sample call to decide; without one the sentences show ? for every value the rule reads

Response Body

The rendered sentences

application/json
  1. response
template*
decision*|

The decision on the sample call; null without one, when the rule does not target it, or when unsupported is not empty

unsupported*array<string>

Capabilities the rule needs that Amiril's own evaluator lacks, so the sample call was not decided; empty when it was

Example Request
curl -X POST 'https://api.amiril.ai/api/rules/preview' \  -H 'Content-Type: application/json' \  -d '{  "rule": {    "property1": null,    "property2": null  }}'
Example Response
{  "template": {    "fail": "string",    "pass": "string",    "model": [      {        "when": "blocked",        "text": "string"      }    ],    "reviewer": {      "action": "string",      "outcome": "string",      "body": "string",      "details": [        "string"      ]    }  },  "decision": {    "action": "string",    "outcome": "string",    "sentence": "string",    "model": [      {        "when": "blocked",        "text": "string"      }    ],    "reviewer": {      "action": "string",      "outcome": "string",      "body": "string",      "details": [        "string"      ]    }  },  "unsupported": [    "string"  ]}

Publish rules

POST
/api/rules/publish

Makes each rule's latest version the one installations run in every environment (every rule with a draft, or the ones named), after the SDK's engine loads each, and writes each environment's new bundle version. Returns the session's environment's bundle. Recorded in the workspace activity log.

Needs a full access token. A read-only token is refused.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Request Body

application/json
  1. body
ruleIds?array<>

Publish only these rules; every rule with a draft when omitted

Items1 <= items <= 500

Response Body

What was published and the bundle now served

application/json
  1. response
published*array<>
bundle*|null
Example Request
curl -X POST 'https://api.amiril.ai/api/rules/publish' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "published": [    {      "ruleId": "string",      "version": 0    }  ],  "bundle": {    "version": "string",    "etag": "string"  }}

One rule

GET
/api/rules/{ruleId}

The rule with every version, newest first, and its mode in the session's environment and in every live environment.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string

The rule's id: a slug, which the model reads when the rule stops a call

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64

Response Body

The rule

application/json
  1. response
rule*
versions*array<>

Newest first

document*

The latest version as the bundle would carry it with the current settings, agents as the names they send

agents*

Since when the rule has had the agents it has now. Counts and backtests from before sinceVersion were for other agents

Example Request
curl -X GET 'https://api.amiril.ai/api/rules/string'
Example Response
{  "rule": {    "id": "string",    "name": "string",    "description": "string",    "mode": "off",    "modes": [      {        "environment": "string",        "mode": "off"      }    ],    "failMode": "open",    "appliesTo": {      "agents": [        "string"      ],      "tools": [        "string"      ]    },    "latestVersion": 0,    "publishedVersion": 0,    "publishedAt": "string",    "createdBy": "string",    "createdAt": "string",    "updatedAt": "string",    "archivedAt": "string",    "warnings": [      {        "code": "agent_unresolved",        "agent": "string",        "message": "string"      }    ],    "liveSince": {      "bundleVersion": "string",      "at": "string"    },    "shown": {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string"    }  },  "versions": [    {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string",      "author": "string",      "changeNote": "string",      "createdAt": "string",      "publishedAt": "string"    }  ],  "document": {    "property1": null,    "property2": null  },  "agents": {    "sinceVersion": 0,    "gained": {      "names": [        "string"      ],      "everyOther": true    }  }}

Edit a rule

PATCH
/api/rules/{ruleId}

A new rule or text is stored as the next draft version. Mode and fail mode take effect at once on a published rule, and each change is recorded in the workspace activity log. The mode changes in the session's environment only, moving its bundle version; the other settings move every environment's. A new id is accepted only before the rule is first published. A new version that changes the agents in the head is refused with 409, whose body says what changes: new_version (at least one agent stays) or replace (no agent stays). Sending agentChange with that kind confirms it; on replace the returned rule is a new one, with a new id, and this one is archived with its history. Either way a backtest of the saved version starts. Unknown fields are refused.

Needs a full access token. A read-only token is refused.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string

The rule's id: a slug, which the model reads when the rule stops a call

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64

Request Body

application/json
  1. body
id?string

A new id; only before the rule is first published

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64
name?string
Length1 <= length <= 200
description?|null
rule?

A new draft version; installations keep the published one until the next publish

text?string

The whole rule as rule text: a new draft version over rule, or over the latest version when rule is omitted

Lengthlength <= 8000
changeNote?|null
mode?string

The mode in the session's environment

Value in"off""shadow""enforce"
failMode?string

What happens to a call the rule targets when the SDK faults before deciding: closed stops it. Applies only while the rule enforces

Value in"open""closed"
agentChange?string

Confirms a new version that changes the agents in the head: the kind the 409 refusal of the same save named. Without it, or with another kind, the save is refused with 409

Value in"new_version""replace"

Response Body

The rule

application/json
  1. response
rule*
versions*array<>

Newest first

document*

The latest version as the bundle would carry it with the current settings, agents as the names they send

agents*

Since when the rule has had the agents it has now. Counts and backtests from before sinceVersion were for other agents

Example Request
curl -X PATCH 'https://api.amiril.ai/api/rules/string' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "rule": {    "id": "string",    "name": "string",    "description": "string",    "mode": "off",    "modes": [      {        "environment": "string",        "mode": "off"      }    ],    "failMode": "open",    "appliesTo": {      "agents": [        "string"      ],      "tools": [        "string"      ]    },    "latestVersion": 0,    "publishedVersion": 0,    "publishedAt": "string",    "createdBy": "string",    "createdAt": "string",    "updatedAt": "string",    "archivedAt": "string",    "warnings": [      {        "code": "agent_unresolved",        "agent": "string",        "message": "string"      }    ],    "liveSince": {      "bundleVersion": "string",      "at": "string"    },    "shown": {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string"    }  },  "versions": [    {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string",      "author": "string",      "changeNote": "string",      "createdAt": "string",      "publishedAt": "string"    }  ],  "document": {    "property1": null,    "property2": null  },  "agents": {    "sinceVersion": 0,    "gained": {      "names": [        "string"      ],      "everyOther": true    }  }}

The issues a rule fixes

GET
/api/rules/{ruleId}/issues

The issues in the session's environment the rule was drafted for, each with its runs since the rule began enforcing there (null while it does not enforce). Empty for a rule nobody drafted from an issue.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string

The rule's id: a slug, which the model reads when the rule stops a call

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64

Response Body

The issues

application/json
  1. response
issues*array<>
Example Request
curl -X GET 'https://api.amiril.ai/api/rules/string/issues'
Example Response
{  "issues": [    {      "id": "string",      "label": "string",      "title": "string",      "detector": "grounding",      "subject": "string",      "state": "open",      "severity": "critical",      "newRuns": 0    }  ]}

Change a rule's mode

POST
/api/rules/{ruleId}/mode

Changes the mode in the session's environment only. Takes effect at once on a published rule, moving that environment's bundle version. Recorded in the workspace activity log with the environment.

Needs a full access token. A read-only token is refused.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string

The rule's id: a slug, which the model reads when the rule stops a call

Match^[a-z0-9]+(-[a-z0-9]+)*$
Lengthlength <= 64

Request Body

application/json
  1. body
mode*string

off: not evaluated. shadow: evaluated and recorded, never acts. enforce: its decision takes effect

Value in"off""shadow""enforce"

Response Body

The rule

application/json
  1. response
rule*
versions*array<>

Newest first

document*

The latest version as the bundle would carry it with the current settings, agents as the names they send

agents*

Since when the rule has had the agents it has now. Counts and backtests from before sinceVersion were for other agents

Example Request
curl -X POST 'https://api.amiril.ai/api/rules/string/mode' \  -H 'Content-Type: application/json' \  -d '{  "mode": "off"}'
Example Response
{  "rule": {    "id": "string",    "name": "string",    "description": "string",    "mode": "off",    "modes": [      {        "environment": "string",        "mode": "off"      }    ],    "failMode": "open",    "appliesTo": {      "agents": [        "string"      ],      "tools": [        "string"      ]    },    "latestVersion": 0,    "publishedVersion": 0,    "publishedAt": "string",    "createdBy": "string",    "createdAt": "string",    "updatedAt": "string",    "archivedAt": "string",    "warnings": [      {        "code": "agent_unresolved",        "agent": "string",        "message": "string"      }    ],    "liveSince": {      "bundleVersion": "string",      "at": "string"    },    "shown": {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string"    }  },  "versions": [    {      "version": 0,      "rule": {        "property1": null,        "property2": null      },      "text": "string",      "author": "string",      "changeNote": "string",      "createdAt": "string",      "publishedAt": "string"    }  ],  "document": {    "property1": null,    "property2": null  },  "agents": {    "sinceVersion": 0,    "gained": {      "names": [        "string"      ],      "everyOther": true    }  }}
GET
/api/backtests/{ruleId}/{version}

The stored backtest of the rule version over the window (24h, 7d or 30d; default 7d): how many past calls it would have fired on, the newest matched calls with links to their runs and the decision sentence for each, the counts per agent, and whether the result still matches the rule's current settings. Status none when never requested. A publish recomputes the default window for the versions it carries.

Any access token can call this, read-only or full.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string
Length1 <= length <= 256
version*integer
Range1 <= value <= 9007199254740991

Query Parameters

window?string
Value in"24h""7d""30d"

Response Body

The result, or status none

application/json
  1. response
ruleId*string
ruleVersion*number
window*string
Value in"24h""7d""30d"
status*string

none: never requested

Value in"none""queued""running""done""failed"
current*|

Whether the stored result was computed from the rule as it stands now (its settings, and the names its agents are seen under); null with no result

requestedAt*string|null
startedAt*string|null
finishedAt*string|null
windowFrom*string|null
windowTo*string|null
runsScanned*number|null
callsScanned*number|null
fired*|

Past calls the rule would have fired on (any action but allow)

errors*|

Past calls on which its evaluation errored

notEvaluable*|

Past calls whose arguments arrived truncated, which a rule reading arguments cannot be evaluated on: neither fired nor passed

truncated*boolean

The cost ceiling stopped the scan at coveredTo

coveredTo*string|null
history*|null
matched*array<>

The newest matched calls, capped; fired is the count

byAgent*array<>

The counts per agent, by the name its calls carried: every agent with a replayed call, sorted by name

error*string|null
caveats*array<>

What a replay of stored spans cannot reproduce, to state beside the numbers

Example Request
curl -X GET 'https://api.amiril.ai/api/backtests/string/1'
Example Response
{  "ruleId": "string",  "ruleVersion": 0,  "window": "24h",  "status": "none",  "current": true,  "requestedAt": "string",  "startedAt": "string",  "finishedAt": "string",  "windowFrom": "string",  "windowTo": "string",  "runsScanned": 0,  "callsScanned": 0,  "fired": 0,  "errors": 0,  "notEvaluable": 0,  "truncated": true,  "coveredTo": "string",  "history": {    "records": 0,    "runs_open": 0,    "sessions": 0,    "evicted_runs": 0,    "evicted_sessions": 0,    "evicted_records_by_age": 0,    "evicted_records_by_size": 0,    "over_limit_events": 0  },  "matched": [    {      "runId": "string",      "spanId": "string",      "link": "string",      "tool": "string",      "agent": "string",      "sessionId": "string",      "at": "string",      "phase": "pre",      "action": "allow",      "outcome": "string",      "sentence": "string"    }  ],  "byAgent": [    {      "agent": "string",      "callsScanned": 0,      "fired": 0,      "errors": 0,      "notEvaluable": 0    }  ],  "error": "string",  "caveats": [    {      "code": "string",      "text": "string"    }  ]}
POST
/api/backtests/{ruleId}/{version}

Queues the backtest of the rule version over the window (default 7d), replacing the stored result when it finishes. Any version can be backtested, drafts included. Poll the read for the result.

Needs a full access token. A read-only token is refused.

Authorization

accessToken
headerAuthorizationBearer <JWT>

An OAuth access token from Amiril's authorization server, the kind an MCP client gets when it connects.

Path Parameters

ruleId*string
Length1 <= length <= 256
version*integer
Range1 <= value <= 9007199254740991

Request Body

application/json
  1. body
window?string
Value in"24h""7d""30d"

Response Body

Queued

application/json
  1. response
ruleId*string
ruleVersion*number
window*string
Value in"24h""7d""30d"
status*string

none: never requested

Value in"none""queued""running""done""failed"
current*|

Whether the stored result was computed from the rule as it stands now (its settings, and the names its agents are seen under); null with no result

requestedAt*string|null
startedAt*string|null
finishedAt*string|null
windowFrom*string|null
windowTo*string|null
runsScanned*number|null
callsScanned*number|null
fired*|

Past calls the rule would have fired on (any action but allow)

errors*|

Past calls on which its evaluation errored

notEvaluable*|

Past calls whose arguments arrived truncated, which a rule reading arguments cannot be evaluated on: neither fired nor passed

truncated*boolean

The cost ceiling stopped the scan at coveredTo

coveredTo*string|null
history*|null
matched*array<>

The newest matched calls, capped; fired is the count

byAgent*array<>

The counts per agent, by the name its calls carried: every agent with a replayed call, sorted by name

error*string|null
caveats*array<>

What a replay of stored spans cannot reproduce, to state beside the numbers

Example Request
curl -X POST 'https://api.amiril.ai/api/backtests/string/1' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "ruleId": "string",  "ruleVersion": 0,  "window": "24h",  "status": "none",  "current": true,  "requestedAt": "string",  "startedAt": "string",  "finishedAt": "string",  "windowFrom": "string",  "windowTo": "string",  "runsScanned": 0,  "callsScanned": 0,  "fired": 0,  "errors": 0,  "notEvaluable": 0,  "truncated": true,  "coveredTo": "string",  "history": {    "records": 0,    "runs_open": 0,    "sessions": 0,    "evicted_runs": 0,    "evicted_sessions": 0,    "evicted_records_by_age": 0,    "evicted_records_by_size": 0,    "over_limit_events": 0  },  "matched": [    {      "runId": "string",      "spanId": "string",      "link": "string",      "tool": "string",      "agent": "string",      "sessionId": "string",      "at": "string",      "phase": "pre",      "action": "allow",      "outcome": "string",      "sentence": "string"    }  ],  "byAgent": [    {      "agent": "string",      "callsScanned": 0,      "fired": 0,      "errors": 0,      "notEvaluable": 0    }  ],  "error": "string",  "caveats": [    {      "code": "string",      "text": "string"    }  ]}