amiril 0.0.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. amiril-0.0.0.dev0/.gitignore +11 -0
  2. amiril-0.0.0.dev0/LICENSE +202 -0
  3. amiril-0.0.0.dev0/PKG-INFO +114 -0
  4. amiril-0.0.0.dev0/README.md +96 -0
  5. amiril-0.0.0.dev0/hatch_build.py +77 -0
  6. amiril-0.0.0.dev0/pyproject.toml +58 -0
  7. amiril-0.0.0.dev0/src/amiril/__init__.py +51 -0
  8. amiril-0.0.0.dev0/src/amiril/_adapters.py +399 -0
  9. amiril-0.0.0.dev0/src/amiril/_engine/__init__.py +1 -0
  10. amiril-0.0.0.dev0/src/amiril/_engine/engine.py +113 -0
  11. amiril-0.0.0.dev0/src/amiril/_engine/expr.py +653 -0
  12. amiril-0.0.0.dev0/src/amiril/_engine/numbers.py +111 -0
  13. amiril-0.0.0.dev0/src/amiril/_engine/regex.py +262 -0
  14. amiril-0.0.0.dev0/src/amiril/_engine/rules.py +192 -0
  15. amiril-0.0.0.dev0/src/amiril/_engine/sentence.py +251 -0
  16. amiril-0.0.0.dev0/src/amiril/_engine/timeparse.py +72 -0
  17. amiril-0.0.0.dev0/src/amiril/_engine/validate.py +863 -0
  18. amiril-0.0.0.dev0/src/amiril/_engine/values.py +273 -0
  19. amiril-0.0.0.dev0/src/amiril/_kernel/__init__.py +1 -0
  20. amiril-0.0.0.dev0/src/amiril/_kernel/bundle.py +245 -0
  21. amiril-0.0.0.dev0/src/amiril/_kernel/coerce.py +103 -0
  22. amiril-0.0.0.dev0/src/amiril/_kernel/events.py +87 -0
  23. amiril-0.0.0.dev0/src/amiril/_kernel/guard.py +1196 -0
  24. amiril-0.0.0.dev0/src/amiril/_kernel/ids.py +66 -0
  25. amiril-0.0.0.dev0/src/amiril/_kernel/messages.py +30 -0
  26. amiril-0.0.0.dev0/src/amiril/_kernel/normalise.py +165 -0
  27. amiril-0.0.0.dev0/src/amiril/_kernel/records.py +131 -0
  28. amiril-0.0.0.dev0/src/amiril/_kernel/store.py +661 -0
  29. amiril-0.0.0.dev0/src/amiril/_runtime.py +617 -0
  30. amiril-0.0.0.dev0/src/amiril/adk.py +577 -0
  31. amiril-0.0.0.dev0/src/amiril/control/__init__.py +25 -0
  32. amiril-0.0.0.dev0/src/amiril/control/_delivery.py +567 -0
  33. amiril-0.0.0.dev0/src/amiril/control/_disk.py +418 -0
  34. amiril-0.0.0.dev0/src/amiril/control/_holds.py +252 -0
  35. amiril-0.0.0.dev0/src/amiril/control/_jsonschema.py +265 -0
  36. amiril-0.0.0.dev0/src/amiril/control/_pathc.py +85 -0
  37. amiril-0.0.0.dev0/src/amiril/control/_records.py +293 -0
  38. amiril-0.0.0.dev0/src/amiril/control/_redact.py +79 -0
  39. amiril-0.0.0.dev0/src/amiril/control/_transport.py +184 -0
  40. amiril-0.0.0.dev0/src/amiril/control/_wire.py +73 -0
  41. amiril-0.0.0.dev0/src/amiril/control/client.py +1313 -0
  42. amiril-0.0.0.dev0/src/amiril/control/config.py +204 -0
  43. amiril-0.0.0.dev0/src/amiril/control/schemas/bundle.response.schema.json +22 -0
  44. amiril-0.0.0.dev0/src/amiril/control/schemas/common.schema.json +593 -0
  45. amiril-0.0.0.dev0/src/amiril/control/schemas/decisions.request.schema.json +558 -0
  46. amiril-0.0.0.dev0/src/amiril/control/schemas/decisions.response.schema.json +23 -0
  47. amiril-0.0.0.dev0/src/amiril/control/schemas/error.response.schema.json +54 -0
  48. amiril-0.0.0.dev0/src/amiril/control/schemas/heartbeat.request.schema.json +305 -0
  49. amiril-0.0.0.dev0/src/amiril/control/schemas/heartbeat.response.schema.json +34 -0
  50. amiril-0.0.0.dev0/src/amiril/control/schemas/hold-create.request.schema.json +138 -0
  51. amiril-0.0.0.dev0/src/amiril/control/schemas/hold.response.schema.json +226 -0
  52. amiril-0.0.0.dev0/src/amiril/control/schemas/installation-register.request.schema.json +492 -0
  53. amiril-0.0.0.dev0/src/amiril/control/schemas/installation-register.response.schema.json +85 -0
  54. amiril-0.0.0.dev0/src/amiril/core.py +89 -0
  55. amiril-0.0.0.dev0/src/amiril/docs/README.md +14 -0
  56. amiril-0.0.0.dev0/src/amiril/docs/durability/langgraph.md +292 -0
  57. amiril-0.0.0.dev0/src/amiril/docs/frameworks/adk.md +141 -0
  58. amiril-0.0.0.dev0/src/amiril/docs/frameworks/langgraph.md +154 -0
  59. amiril-0.0.0.dev0/src/amiril/docs/frameworks/no-framework.md +238 -0
  60. amiril-0.0.0.dev0/src/amiril/docs/frameworks/write-an-adapter.md +203 -0
  61. amiril-0.0.0.dev0/src/amiril/durable.py +342 -0
  62. amiril-0.0.0.dev0/src/amiril/langgraph.py +746 -0
  63. amiril-0.0.0.dev0/src/amiril/plain.py +454 -0
  64. amiril-0.0.0.dev0/src/amiril/py.typed +0 -0
  65. amiril-0.0.0.dev0/src/amiril/seams.py +357 -0
  66. amiril-0.0.0.dev0/src/amiril/testing.py +21 -0
@@ -0,0 +1,11 @@
1
+ node_modules/
2
+ dist/
3
+ .venv/
4
+ __pycache__/
5
+ *.egg-info/
6
+ .pytest_cache/
7
+ .DS_Store
8
+ .env
9
+ # Docs copied into each npm package at pack time (typescript/scripts/bundle-docs.mjs);
10
+ # the source is the root docs/ folder.
11
+ typescript/packages/*/docs/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.5
2
+ Name: amiril
3
+ Version: 0.0.0.dev0
4
+ Summary: Check an agent's tool calls against rules before they run, through the agent framework's native hooks.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Provides-Extra: adk
9
+ Requires-Dist: google-adk>=2.11; extra == 'adk'
10
+ Provides-Extra: crewai
11
+ Provides-Extra: langgraph
12
+ Requires-Dist: langchain-core>=1.5; extra == 'langgraph'
13
+ Requires-Dist: langchain>=1.3; extra == 'langgraph'
14
+ Requires-Dist: langgraph-prebuilt>=1.1; extra == 'langgraph'
15
+ Requires-Dist: langgraph>=1.2; extra == 'langgraph'
16
+ Provides-Extra: otel
17
+ Description-Content-Type: text/markdown
18
+
19
+ # amiril (Python)
20
+
21
+ The Python Amiril SDK: the rule engine (`spec/edoc.md`) and the kernel
22
+ (`spec/kernel.md`) with no runtime dependencies, `amiril.init()` and
23
+ `amiril.instrument()`, and the framework adapters as extras:
24
+ `amiril[adk]` (Google ADK) and `amiril[langgraph]` (LangGraph and
25
+ LangChain `create_agent`). `amiril.plain` is the same checks for an agent
26
+ written by hand, with no extra. Getting started: `docs/frameworks/adk.md`,
27
+ `docs/frameworks/langgraph.md` and `docs/frameworks/no-framework.md`.
28
+
29
+ ```
30
+ src/amiril/
31
+ __init__.py init(), instrument(), the handle (_runtime.py) and the install errors
32
+ adk.py the ADK adapter: one plugin, first in the app's plugin list
33
+ langgraph.py the LangGraph adapter: create_agent middleware and a ToolNode for StateGraph
34
+ plain.py no framework (spec/plain.md): name an agent, wrap its tools, mark a run,
35
+ or check each call by hand; also what an adapter for another framework calls
36
+ _adapters.py what the adapters share: parent link, faults, coercion, coverage entries
37
+ core.py the public surface adapters import: Guard, RunContext, CallRecord,
38
+ Decision, Outcome, load_document, coerce_args, ...
39
+ seams.py the interfaces between the kernel, the adapters and the control-plane
40
+ client (bundle source, decision sink, resolver, registration reporter,
41
+ kernel stats), each with a local-only implementation
42
+ control/ the control-plane client (spec/protocol.md): registration, rule sync,
43
+ heartbeats, decision delivery and spool, holds, redaction, path C
44
+ testing.py InjectedFault, the fault-injection seam the conformance suite uses
45
+ _engine/ loader and validator, evaluator, sentences
46
+ _kernel/ records, history store, Guard, decision lines, coercion, ids
47
+ tests/
48
+ control/ the client against a fake control plane that schema-checks every request
49
+ (../../spec/protocol), and an integration test against the real ingest
50
+ service, skipped unless AMIRIL_TEST_ENDPOINT and AMIRIL_TEST_KEY are set
51
+ conformance/ the runner over ../../conformance (scenarios and golden lines, probes,
52
+ bad documents, catalogue, coercion)
53
+ frameworks/ the scenarios through real ADK and LangGraph runs (scripted models), the
54
+ span constants, install order, coverage, tool-error parity, the examples
55
+ unit/ eviction, history report, swap, tool_id, holds and faults, init()
56
+ examples/ runnable offline examples behind the getting-started pages
57
+ scripts/
58
+ test-installed.sh build the wheel, install it into a fresh venv, run the suite against it
59
+ bench.py latency benchmark: 50 rules, 200 prior calls, p50 and p99 per decision
60
+ ```
61
+
62
+ Running the control-plane client in production:
63
+
64
+ - **SIGTERM loses queued records** unless the host acts: Python's default
65
+ SIGTERM handling skips `atexit`, so the client neither sends nor spools
66
+ what is queued. Call the handle's `shutdown()` (or the client's) from a
67
+ SIGTERM handler, or install one that raises `SystemExit`.
68
+ - **Forking servers** (gunicorn `--preload`, celery prefork) are supported:
69
+ each child re-initialises the client with a new process id and starts it
70
+ on first use.
71
+ - **Proxies** come from `HTTPS_PROXY`/`HTTP_PROXY` and `NO_PROXY`.
72
+ - **Disk**: the spool and bundle cache live in `AMIRIL_CACHE_DIR`, else
73
+ `$XDG_CACHE_HOME/amiril`, else `<tmp>/amiril-<uid>`, a directory that must
74
+ be private to the user (0700); otherwise they are not used.
75
+ - **DNS** is not bounded by the client's timeouts (hold reads included); the
76
+ system resolver's own timeouts apply.
77
+
78
+ Develop with `uv sync` then `uv run pytest`; for the framework tests,
79
+ `uv sync --group frameworks --python 3.12`. Prove publishability with
80
+ `scripts/test-installed.sh [3.11]` and, with the frameworks,
81
+ `scripts/test-installed.sh 3.12 frameworks`, which is what CI runs.
82
+
83
+ With a framework, local-only (no API key, no network):
84
+
85
+ ```python
86
+ import amiril
87
+
88
+ amiril.init(rules_file="rules.json")
89
+ amiril.instrument(app) # an ADK App or Runner; for LangGraph see docs/frameworks/langgraph.md
90
+ ```
91
+
92
+ The kernel on its own:
93
+
94
+ ```python
95
+ from amiril.core import Guard, RunContext, load_document_file
96
+
97
+ guard = Guard(mode="enforce", document=load_document_file("rules.json"))
98
+ ctx = RunContext(run_id="run-1", agent_id="planner")
99
+ outcome = guard.before_call(ctx, "call-1", "update_record", {"id": "rec_1", "count": 12}, batch_id="turn-1")
100
+ if outcome.proceeds:
101
+ result = update_record(id="rec_1", count=12)
102
+ guard.after_call(ctx, "call-1", raw_result=result)
103
+ else:
104
+ result = outcome.message # what the model is told
105
+ guard.end_run(ctx)
106
+ ```
107
+
108
+ ## For AI assistants
109
+
110
+ The installed package carries its docs for the installed version in
111
+ `amiril/docs/` under site-packages; start at `amiril/docs/README.md`. They
112
+ need no network call. Find the folder with
113
+ `python -c "import amiril, pathlib; print(pathlib.Path(amiril.__file__).parent / 'docs')"`.
114
+ Fuller docs: https://docs.amiril.ai/llms.txt
@@ -0,0 +1,96 @@
1
+ # amiril (Python)
2
+
3
+ The Python Amiril SDK: the rule engine (`spec/edoc.md`) and the kernel
4
+ (`spec/kernel.md`) with no runtime dependencies, `amiril.init()` and
5
+ `amiril.instrument()`, and the framework adapters as extras:
6
+ `amiril[adk]` (Google ADK) and `amiril[langgraph]` (LangGraph and
7
+ LangChain `create_agent`). `amiril.plain` is the same checks for an agent
8
+ written by hand, with no extra. Getting started: `docs/frameworks/adk.md`,
9
+ `docs/frameworks/langgraph.md` and `docs/frameworks/no-framework.md`.
10
+
11
+ ```
12
+ src/amiril/
13
+ __init__.py init(), instrument(), the handle (_runtime.py) and the install errors
14
+ adk.py the ADK adapter: one plugin, first in the app's plugin list
15
+ langgraph.py the LangGraph adapter: create_agent middleware and a ToolNode for StateGraph
16
+ plain.py no framework (spec/plain.md): name an agent, wrap its tools, mark a run,
17
+ or check each call by hand; also what an adapter for another framework calls
18
+ _adapters.py what the adapters share: parent link, faults, coercion, coverage entries
19
+ core.py the public surface adapters import: Guard, RunContext, CallRecord,
20
+ Decision, Outcome, load_document, coerce_args, ...
21
+ seams.py the interfaces between the kernel, the adapters and the control-plane
22
+ client (bundle source, decision sink, resolver, registration reporter,
23
+ kernel stats), each with a local-only implementation
24
+ control/ the control-plane client (spec/protocol.md): registration, rule sync,
25
+ heartbeats, decision delivery and spool, holds, redaction, path C
26
+ testing.py InjectedFault, the fault-injection seam the conformance suite uses
27
+ _engine/ loader and validator, evaluator, sentences
28
+ _kernel/ records, history store, Guard, decision lines, coercion, ids
29
+ tests/
30
+ control/ the client against a fake control plane that schema-checks every request
31
+ (../../spec/protocol), and an integration test against the real ingest
32
+ service, skipped unless AMIRIL_TEST_ENDPOINT and AMIRIL_TEST_KEY are set
33
+ conformance/ the runner over ../../conformance (scenarios and golden lines, probes,
34
+ bad documents, catalogue, coercion)
35
+ frameworks/ the scenarios through real ADK and LangGraph runs (scripted models), the
36
+ span constants, install order, coverage, tool-error parity, the examples
37
+ unit/ eviction, history report, swap, tool_id, holds and faults, init()
38
+ examples/ runnable offline examples behind the getting-started pages
39
+ scripts/
40
+ test-installed.sh build the wheel, install it into a fresh venv, run the suite against it
41
+ bench.py latency benchmark: 50 rules, 200 prior calls, p50 and p99 per decision
42
+ ```
43
+
44
+ Running the control-plane client in production:
45
+
46
+ - **SIGTERM loses queued records** unless the host acts: Python's default
47
+ SIGTERM handling skips `atexit`, so the client neither sends nor spools
48
+ what is queued. Call the handle's `shutdown()` (or the client's) from a
49
+ SIGTERM handler, or install one that raises `SystemExit`.
50
+ - **Forking servers** (gunicorn `--preload`, celery prefork) are supported:
51
+ each child re-initialises the client with a new process id and starts it
52
+ on first use.
53
+ - **Proxies** come from `HTTPS_PROXY`/`HTTP_PROXY` and `NO_PROXY`.
54
+ - **Disk**: the spool and bundle cache live in `AMIRIL_CACHE_DIR`, else
55
+ `$XDG_CACHE_HOME/amiril`, else `<tmp>/amiril-<uid>`, a directory that must
56
+ be private to the user (0700); otherwise they are not used.
57
+ - **DNS** is not bounded by the client's timeouts (hold reads included); the
58
+ system resolver's own timeouts apply.
59
+
60
+ Develop with `uv sync` then `uv run pytest`; for the framework tests,
61
+ `uv sync --group frameworks --python 3.12`. Prove publishability with
62
+ `scripts/test-installed.sh [3.11]` and, with the frameworks,
63
+ `scripts/test-installed.sh 3.12 frameworks`, which is what CI runs.
64
+
65
+ With a framework, local-only (no API key, no network):
66
+
67
+ ```python
68
+ import amiril
69
+
70
+ amiril.init(rules_file="rules.json")
71
+ amiril.instrument(app) # an ADK App or Runner; for LangGraph see docs/frameworks/langgraph.md
72
+ ```
73
+
74
+ The kernel on its own:
75
+
76
+ ```python
77
+ from amiril.core import Guard, RunContext, load_document_file
78
+
79
+ guard = Guard(mode="enforce", document=load_document_file("rules.json"))
80
+ ctx = RunContext(run_id="run-1", agent_id="planner")
81
+ outcome = guard.before_call(ctx, "call-1", "update_record", {"id": "rec_1", "count": 12}, batch_id="turn-1")
82
+ if outcome.proceeds:
83
+ result = update_record(id="rec_1", count=12)
84
+ guard.after_call(ctx, "call-1", raw_result=result)
85
+ else:
86
+ result = outcome.message # what the model is told
87
+ guard.end_run(ctx)
88
+ ```
89
+
90
+ ## For AI assistants
91
+
92
+ The installed package carries its docs for the installed version in
93
+ `amiril/docs/` under site-packages; start at `amiril/docs/README.md`. They
94
+ need no network call. Find the folder with
95
+ `python -c "import amiril, pathlib; print(pathlib.Path(amiril.__file__).parent / 'docs')"`.
96
+ Fuller docs: https://docs.amiril.ai/llms.txt
@@ -0,0 +1,77 @@
1
+ """Bundle the docs pages for Python into the package at build time.
2
+
3
+ An AI assistant can then read the docs for the exact version installed from
4
+ ``<site-packages>/amiril/docs/`` with no network call. The source is the
5
+ repository's ``docs/`` folder, outside this project, so the pages and a
6
+ generated index are force-included: into ``amiril/docs/`` in the wheel and
7
+ ``src/amiril/docs/`` in the sdist. A wheel built from the sdist (what
8
+ ``uv build`` does) finds them already in ``src/amiril`` and packages them
9
+ with the rest of the code.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import re
15
+ import shutil
16
+ import tempfile
17
+ from pathlib import Path
18
+ from typing import Any
19
+
20
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
21
+
22
+ # The pages the Python package ships, as paths under the repository's docs/.
23
+ PAGES = (
24
+ "frameworks/adk.md",
25
+ "frameworks/langgraph.md",
26
+ "frameworks/no-framework.md",
27
+ "frameworks/write-an-adapter.md",
28
+ "durability/langgraph.md",
29
+ )
30
+ LLMS = "https://docs.amiril.ai/llms.txt"
31
+
32
+
33
+ def _index(version: str, docs: Path) -> str:
34
+ """The index: one line per page (its title), the version, and where the rest lives."""
35
+ lines = []
36
+ for page in PAGES:
37
+ title = re.search(r"^# (.+)$", (docs / page).read_text(encoding="utf-8"), re.M)
38
+ if title is None:
39
+ raise ValueError(f'docs/{page} has no "# " title')
40
+ lines.append(f"- [{page}]({page}): {title.group(1)}")
41
+ pages = "\n".join(lines)
42
+ return f"""# amiril {version}: docs
43
+
44
+ These pages describe amiril {version}, the version installed beside this
45
+ file. They were copied from the Amiril SDK repository when the package was
46
+ built, so they match the code you have. Where a page shows Python and
47
+ TypeScript side by side, this package is the Python one.
48
+
49
+ {pages}
50
+
51
+ Fuller docs, for every package and the Amiril control plane: {LLMS}
52
+ """
53
+
54
+
55
+ class DocsHook(BuildHookInterface):
56
+ PLUGIN_NAME = "custom"
57
+
58
+ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
59
+ root = Path(self.root)
60
+ docs = root.parent / "docs"
61
+ if not docs.is_dir():
62
+ # Building the wheel from an unpacked sdist: the sdist carries the pages in src/amiril/docs.
63
+ if not (root / "src/amiril/docs/README.md").is_file():
64
+ raise FileNotFoundError("no docs to bundle: neither ../docs nor src/amiril/docs")
65
+ return
66
+ dest = "amiril/docs" if self.target_name == "wheel" else "src/amiril/docs"
67
+ self._staging = Path(tempfile.mkdtemp(prefix="amiril-docs-"))
68
+ index = self._staging / "README.md"
69
+ index.write_text(_index(self.metadata.version, docs), encoding="utf-8")
70
+ build_data["force_include"][str(index)] = f"{dest}/README.md"
71
+ for page in PAGES:
72
+ build_data["force_include"][str(docs / page)] = f"{dest}/{page}"
73
+
74
+ def finalize(self, version: str, build_data: dict[str, Any], artifact_path: str) -> None:
75
+ staging = getattr(self, "_staging", None)
76
+ if staging is not None:
77
+ shutil.rmtree(staging, ignore_errors=True)
@@ -0,0 +1,58 @@
1
+ [project]
2
+ name = "amiril"
3
+ version = "0.0.0.dev0"
4
+ description = "Check an agent's tool calls against rules before they run, through the agent framework's native hooks."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.11"
9
+ dependencies = []
10
+
11
+ [project.optional-dependencies]
12
+ # A floor and no ceiling: the lowest release the adapter works with. The
13
+ # tested range is `TESTED` in each adapter, and outside it the adapter keeps
14
+ # running and reports `untested_framework_version`. A ceiling here would only
15
+ # make an install fail the day a framework ships a minor.
16
+ adk = ["google-adk>=2.11"]
17
+ langgraph = [
18
+ "langgraph>=1.2",
19
+ "langgraph-prebuilt>=1.1",
20
+ "langchain>=1.3",
21
+ "langchain-core>=1.5",
22
+ ]
23
+ crewai = []
24
+ otel = []
25
+
26
+ [dependency-groups]
27
+ dev = ["pytest>=8"]
28
+ # The framework conformance and adapter tests: the extras plus the span capture
29
+ # (OpenTelemetry SDK, and OpenInference for LangChain's tool spans).
30
+ frameworks = [
31
+ "pytest>=8",
32
+ "amiril[adk,langgraph]",
33
+ "opentelemetry-sdk>=1.30",
34
+ "openinference-instrumentation-langchain>=0.1.70",
35
+ # LangGraph's file checkpointer, for the restart test (tests/durability): the
36
+ # kill-and-resume needs a checkpoint that outlives the process.
37
+ "langgraph-checkpoint-sqlite>=3.0",
38
+ ]
39
+
40
+ [build-system]
41
+ requires = ["hatchling"]
42
+ build-backend = "hatchling.build"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/amiril"]
46
+
47
+ [tool.hatch.build.targets.sdist]
48
+ include = ["src/amiril", "README.md", "pyproject.toml", "hatch_build.py"]
49
+
50
+ # Copies the docs pages for Python, and an index, into the package (hatch_build.py).
51
+ [tool.hatch.build.hooks.custom]
52
+
53
+ [tool.pytest.ini_options]
54
+ testpaths = ["tests"]
55
+ addopts = "-q"
56
+ markers = [
57
+ "tested_releases(adapter): skip outside the adapter's tested framework releases (tests/frameworks/conftest.py)",
58
+ ]
@@ -0,0 +1,51 @@
1
+ """Amiril SDK: check an agent's tool calls against rules before they run.
2
+
3
+ import amiril
4
+ amiril.init(rules_file="rules.json")
5
+ amiril.instrument(app) # an ADK App or Runner, a LangGraph graph
6
+ agent = amiril.plain.Agent("name") # or no framework at all
7
+
8
+ `amiril.init()` and `amiril.instrument()` are the entry points. The core
9
+ (`amiril.core`) is the rule engine and the kernel every framework adapter
10
+ builds on; `amiril.seams` names the interfaces between the kernel, the
11
+ adapters and the control-plane client. The adapters are `amiril.adk` and
12
+ `amiril.langgraph` (extras `amiril[adk]`, `amiril[langgraph]`), imported only
13
+ when used, so importing `amiril` never imports a framework. `amiril.plain`
14
+ is the same checks for an agent written by hand.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import importlib
20
+ from typing import Any
21
+
22
+ __version__ = "0.0.0.dev0"
23
+
24
+ from ._adapters import AmirilInstallError, HookOrderError, NotInitialisedError # noqa: E402
25
+ from ._runtime import Amiril, init, instrument # noqa: E402
26
+ from .core import CallRecord, Decision, DocumentError, Guard, Outcome, RunContext # noqa: E402
27
+
28
+ _ADAPTERS = ("adk", "langgraph", "plain")
29
+
30
+
31
+ def __getattr__(name: str) -> Any:
32
+ if name in _ADAPTERS:
33
+ return importlib.import_module(f"{__name__}.{name}")
34
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
35
+
36
+
37
+ __all__ = [
38
+ "Amiril",
39
+ "AmirilInstallError",
40
+ "CallRecord",
41
+ "Decision",
42
+ "DocumentError",
43
+ "Guard",
44
+ "HookOrderError",
45
+ "NotInitialisedError",
46
+ "Outcome",
47
+ "RunContext",
48
+ "__version__",
49
+ "init",
50
+ "instrument",
51
+ ]