Metadata-Version: 2.5
Name: amiril
Version: 0.1.0
Summary: Check an agent's tool calls against rules before they run, through the agent framework's native hooks.
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.11
Provides-Extra: adk
Requires-Dist: google-adk>=2.11; extra == 'adk'
Provides-Extra: crewai
Provides-Extra: langgraph
Requires-Dist: langchain-core>=1.5; extra == 'langgraph'
Requires-Dist: langchain>=1.3; extra == 'langgraph'
Requires-Dist: langgraph-prebuilt>=1.1; extra == 'langgraph'
Requires-Dist: langgraph>=1.2; extra == 'langgraph'
Provides-Extra: otel
Description-Content-Type: text/markdown

# amiril (Python)

The Python Amiril SDK: the rule engine (`spec/edoc.md`) and the kernel
(`spec/kernel.md`) with no runtime dependencies, `amiril.init()` and
`amiril.instrument()`, and the framework adapters as extras:
`amiril[adk]` (Google ADK) and `amiril[langgraph]` (LangGraph and
LangChain `create_agent`). `amiril.plain` is the same checks for an agent
written by hand, with no extra. Getting started: `docs/frameworks/adk.md`,
`docs/frameworks/langgraph.md` and `docs/frameworks/no-framework.md`.

```
src/amiril/
  __init__.py      init(), instrument(), the handle (_runtime.py) and the install errors
  adk.py           the ADK adapter: one plugin, first in the app's plugin list
  langgraph.py     the LangGraph adapter: create_agent middleware and a ToolNode for StateGraph
  plain.py         no framework (spec/plain.md): name an agent, wrap its tools, mark a run,
                   or check each call by hand; also what an adapter for another framework calls
  _adapters.py     what the adapters share: parent link, faults, coercion, coverage entries
  core.py          the public surface adapters import: Guard, RunContext, CallRecord,
                   Decision, Outcome, load_document, coerce_args, ...
  seams.py         the interfaces between the kernel, the adapters and the control-plane
                   client (bundle source, decision sink, resolver, registration reporter,
                   kernel stats), each with a local-only implementation
  control/         the control-plane client (spec/protocol.md): registration, rule sync,
                   heartbeats, decision delivery and spool, holds, redaction, path C
  testing.py       InjectedFault, the fault-injection seam the conformance suite uses
  _engine/         loader and validator, evaluator, sentences
  _kernel/         records, history store, Guard, decision lines, coercion, ids
tests/
  control/         the client against a fake control plane that schema-checks every request
                   (../../spec/protocol), and an integration test against the real ingest
                   service, skipped unless AMIRIL_TEST_ENDPOINT and AMIRIL_TEST_KEY are set
  conformance/     the runner over ../../conformance (scenarios and golden lines, probes,
                   bad documents, catalogue, coercion)
  frameworks/      the scenarios through real ADK and LangGraph runs (scripted models), the
                   span constants, install order, coverage, tool-error parity, the examples
  unit/            eviction, history report, swap, tool_id, holds and faults, init()
examples/          runnable offline examples behind the getting-started pages
scripts/
  test-installed.sh  build the wheel, install it into a fresh venv, run the suite against it
  bench.py           latency benchmark: 50 rules, 200 prior calls, p50 and p99 per decision
```

Running the control-plane client in production:

- **SIGTERM loses queued records** unless the host acts: Python's default
  SIGTERM handling skips `atexit`, so the client neither sends nor spools
  what is queued. Call the handle's `shutdown()` (or the client's) from a
  SIGTERM handler, or install one that raises `SystemExit`.
- **Forking servers** (gunicorn `--preload`, celery prefork) are supported:
  each child re-initialises the client with a new process id and starts it
  on first use.
- **Proxies** come from `HTTPS_PROXY`/`HTTP_PROXY` and `NO_PROXY`.
- **Disk**: the spool and bundle cache live in `AMIRIL_CACHE_DIR`, else
  `$XDG_CACHE_HOME/amiril`, else `<tmp>/amiril-<uid>`, a directory that must
  be private to the user (0700); otherwise they are not used.
- **DNS** is not bounded by the client's timeouts (hold reads included); the
  system resolver's own timeouts apply.

Develop with `uv sync` then `uv run pytest`; for the framework tests,
`uv sync --group frameworks --python 3.12`. Prove publishability with
`scripts/test-installed.sh [3.11]` and, with the frameworks,
`scripts/test-installed.sh 3.12 frameworks`, which is what CI runs.

With a framework, local-only (no API key, no network):

```python
import amiril

amiril.init(rules_file="rules.json")
amiril.instrument(app)  # an ADK App or Runner; for LangGraph see docs/frameworks/langgraph.md
```

The kernel on its own:

```python
from amiril.core import Guard, RunContext, load_document_file

guard = Guard(mode="enforce", document=load_document_file("rules.json"))
ctx = RunContext(run_id="run-1", agent_id="planner")
outcome = guard.before_call(ctx, "call-1", "update_record", {"id": "rec_1", "count": 12}, batch_id="turn-1")
if outcome.proceeds:
    result = update_record(id="rec_1", count=12)
    guard.after_call(ctx, "call-1", raw_result=result)
else:
    result = outcome.message  # what the model is told
guard.end_run(ctx)
```

## For AI assistants

The installed package carries its docs for the installed version in
`amiril/docs/` under site-packages; start at `amiril/docs/README.md`. They
need no network call. Find the folder with
`python -c "import amiril, pathlib; print(pathlib.Path(amiril.__file__).parent / 'docs')"`.
Fuller docs: https://docs.amiril.ai/llms.txt
