agindow 0.1.0a0__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.
- agindow-0.1.0a0/.gitignore +5 -0
- agindow-0.1.0a0/LICENSE +202 -0
- agindow-0.1.0a0/NOTICE +36 -0
- agindow-0.1.0a0/PKG-INFO +133 -0
- agindow-0.1.0a0/README.md +118 -0
- agindow-0.1.0a0/examples/offline.py +34 -0
- agindow-0.1.0a0/pyproject.toml +55 -0
- agindow-0.1.0a0/scripts/bench.py +72 -0
- agindow-0.1.0a0/scripts/build.py +29 -0
- agindow-0.1.0a0/scripts/parity.py +118 -0
- agindow-0.1.0a0/src/agindow/__init__.py +52 -0
- agindow-0.1.0a0/src/agindow/_guest.wasm +0 -0
- agindow-0.1.0a0/src/agindow/capture.py +54 -0
- agindow-0.1.0a0/src/agindow/config.py +96 -0
- agindow-0.1.0a0/src/agindow/identity_source.py +54 -0
- agindow-0.1.0a0/src/agindow/machine_auth.py +155 -0
- agindow-0.1.0a0/src/agindow/primitive.py +174 -0
- agindow-0.1.0a0/src/agindow/py.typed +0 -0
- agindow-0.1.0a0/src/agindow/remote.py +153 -0
- agindow-0.1.0a0/src/agindow/sdk.py +136 -0
- agindow-0.1.0a0/src/agindow/types.py +101 -0
- agindow-0.1.0a0/src/agindow/wasm.py +225 -0
- agindow-0.1.0a0/tests/test_api_key_format.py +16 -0
- agindow-0.1.0a0/tests/test_boundaries.py +150 -0
- agindow-0.1.0a0/tests/test_capture.py +20 -0
- agindow-0.1.0a0/tests/test_config.py +54 -0
- agindow-0.1.0a0/tests/test_machine_auth.py +107 -0
- agindow-0.1.0a0/tests/test_model.py +29 -0
- agindow-0.1.0a0/tests/test_package.py +89 -0
- agindow-0.1.0a0/tests/test_parity.py +33 -0
- agindow-0.1.0a0/tests/test_public.py +17 -0
- agindow-0.1.0a0/tests/test_remote.py +69 -0
- agindow-0.1.0a0/tests/test_sdk.py +168 -0
- agindow-0.1.0a0/tests/test_wasm.py +65 -0
- agindow-0.1.0a0/uv.lock +465 -0
agindow-0.1.0a0/LICENSE
ADDED
|
@@ -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 2026 AGINDOW
|
|
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.
|
agindow-0.1.0a0/NOTICE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
AGINDOW
|
|
2
|
+
Copyright 2026 AGINDOW
|
|
3
|
+
|
|
4
|
+
This product includes software developed at AGINDOW.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
7
|
+
use these files except in compliance with the License. A copy of the License
|
|
8
|
+
is distributed with this work, and is also available at:
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
--------------------------------------------------------------------------------
|
|
13
|
+
Trademark notice
|
|
14
|
+
--------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
"AGINDOW" is a trademark of AGINDOW. The Apache License, Version 2.0 does
|
|
17
|
+
**not** grant permission to use this name, the AGINDOW word mark, or any other
|
|
18
|
+
trademark or logo of the Licensor. See Section 6 of the License.
|
|
19
|
+
|
|
20
|
+
The License permits use of the name only as reasonably necessary to describe
|
|
21
|
+
the origin of the work and to reproduce the content of this NOTICE file.
|
|
22
|
+
|
|
23
|
+
Vendors and redistributors who wish to refer to the project by name in their
|
|
24
|
+
own documentation or user interfaces should write something like "built with
|
|
25
|
+
AGINDOW" rather than implying endorsement or affiliation. Please contact the
|
|
26
|
+
Licensor for permission to use the mark in any other way.
|
|
27
|
+
|
|
28
|
+
--------------------------------------------------------------------------------
|
|
29
|
+
Scope
|
|
30
|
+
--------------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
This NOTICE applies to the Work distributed under the Apache License, Version
|
|
33
|
+
2.0. Portions of this repository designated as proprietary in
|
|
34
|
+
`tasks/TECH_STACK.md` §6 — the control plane, registry, and dashboard — are not
|
|
35
|
+
covered by the Apache License and are licensed separately. Those portions do
|
|
36
|
+
not exist in this repository yet.
|
agindow-0.1.0a0/PKG-INFO
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agindow
|
|
3
|
+
Version: 0.1.0a0
|
|
4
|
+
Summary: API drift firewall for AI agents on Python (Rust/WASM)
|
|
5
|
+
Project-URL: Homepage, https://github.com/agindow/sdk
|
|
6
|
+
Project-URL: Repository, https://github.com/agindow/sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/agindow/sdk/issues
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Keywords: agents,ai,api,drift,firewall,guard,llm,observability,sdk,wasm
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: wasmtime==46.0.1
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# agindow (Python)
|
|
17
|
+
|
|
18
|
+
API drift firewall for AI agents on Python 3.11+ — repair drift in-flight, prove
|
|
19
|
+
the write was correct. **Pre-alpha** on PyPI as `agindow`. Loads the **identical
|
|
20
|
+
WASM bytes** built for `agindow` through Wasmtime. Python provides
|
|
21
|
+
callable/configuration/availability glue — not a second drift engine.
|
|
22
|
+
|
|
23
|
+
The default engine detects nothing until you configure protection. Statistical
|
|
24
|
+
windows require explicit local baseline/live selections.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install agindow
|
|
30
|
+
# or: uv add agindow
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The wheel includes the prebuilt WASM guest. You do **not** need Rust, Node, or a
|
|
34
|
+
monorepo checkout to use the SDK.
|
|
35
|
+
|
|
36
|
+
## Decorators, async and contexts
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from agindow import Agindow, guard
|
|
40
|
+
|
|
41
|
+
@guard(mode="repair", tool="customers.create", operation="write")
|
|
42
|
+
def create_customer(email: str) -> dict[str, str]:
|
|
43
|
+
return {"email": email}
|
|
44
|
+
|
|
45
|
+
sdk = Agindow(mode="observe")
|
|
46
|
+
|
|
47
|
+
@sdk.guard(tool="customers.read", operation="read")
|
|
48
|
+
async def read_customer() -> dict[str, str]:
|
|
49
|
+
return {"id": "fixture"}
|
|
50
|
+
|
|
51
|
+
with sdk.context(mode="strict"):
|
|
52
|
+
# Only calls through this SDK's guards use the scoped configuration.
|
|
53
|
+
pass
|
|
54
|
+
# `async with sdk.context(...)` is supported as well.
|
|
55
|
+
sdk.close()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Context managers scope guarded calls; they cannot intercept arbitrary Python
|
|
59
|
+
statements. Overrides use ContextVar, nest and remain isolated across async
|
|
60
|
+
tasks. Each call freezes configuration until completion. `configure(mode="repair")`
|
|
61
|
+
changes future calls. `sdk.ready` is a synchronous boolean after local loading
|
|
62
|
+
(unlike Node’s startup Promise); `sdk.load_error` retains a loading failure.
|
|
63
|
+
Loading failures and retired guests preserve upstream results and emit one
|
|
64
|
+
bypass per call. `close()` is safe for shutdown; subsequent calls bypass.
|
|
65
|
+
|
|
66
|
+
The wrapper preserves `__name__`, documentation, annotations, signatures,
|
|
67
|
+
bound receivers and arguments. ParamSpec retains Pydantic model types without
|
|
68
|
+
a mandatory Pydantic dependency. Model results retain their original identity;
|
|
69
|
+
only a detached `model_dump(mode="json")` projection enters inspection.
|
|
70
|
+
|
|
71
|
+
## Configuration and feedback
|
|
72
|
+
|
|
73
|
+
Supported fields (snake_case): `mode`, `fail_closed`, `api_key`, `endpoint`,
|
|
74
|
+
`allowed_tools` (`"*"` or a tuple), `deny_tools`, `buffer` and `on_event`.
|
|
75
|
+
Resolution: explicit keywords > environment > nearest JSON `.agindowrc` >
|
|
76
|
+
defaults. Shared env vars match Node (`AGINDOW_MODE`, `AGINDOW_KEY`,
|
|
77
|
+
`AGINDOW_ENDPOINT`, `AGINDOW_BUFFER`, `AGINDOW_FAIL_CLOSED`). Invalid explicit
|
|
78
|
+
or environment values raise `AgindowSetupError` before a call.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from agindow import AgindowDriftError
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
create_customer("fixture@example.test")
|
|
85
|
+
except AgindowDriftError as error:
|
|
86
|
+
print(error.code, error.tool, error.drift_class, error.drift_id)
|
|
87
|
+
print(error.hint, error.audit_url)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Request halts dispatch zero times. Response halts retain `error.outcome` and
|
|
91
|
+
warn against blind replay. Upstream exceptions survive as `error.__cause__`.
|
|
92
|
+
Missing audit IDs/URLs remain empty rather than fabricated.
|
|
93
|
+
|
|
94
|
+
`on(type, handler)` returns an unsubscribe callback; `recent()` returns an
|
|
95
|
+
immutable tuple of retained events. `buffer=0` disables retention. This is local
|
|
96
|
+
telemetry, not hosted audit delivery.
|
|
97
|
+
|
|
98
|
+
## Shared-core validation and limits
|
|
99
|
+
|
|
100
|
+
Parity fixtures run both public wrappers against the same WASM guest. The
|
|
101
|
+
paired local agent-loop benchmark gates added p50 <100 µs on the default
|
|
102
|
+
NullEngine only (excludes model/network/import/statistical work).
|
|
103
|
+
|
|
104
|
+
Python `wrap` currently accepts callables. Node-specific tool/client/HTTP
|
|
105
|
+
adapters, Nango codegen, OTel spans, report CLI and remote configuration/audit
|
|
106
|
+
transports are outside this package. No Python framework adapter or streaming
|
|
107
|
+
qualification is claimed. Inspection is bounded to detached JSON projections.
|
|
108
|
+
|
|
109
|
+
## Remote fail-open API
|
|
110
|
+
|
|
111
|
+
Local decorators stay offline. Remote execution is a separate HTTP API using
|
|
112
|
+
stdlib HTTP transport; it never redirects or retries through AGINDOW:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from agindow import RemoteEnvelope, RemoteOptions, guard_remote
|
|
116
|
+
|
|
117
|
+
request = RemoteEnvelope("vendor.read", "example", "read", {}, "observe")
|
|
118
|
+
result = guard_remote(
|
|
119
|
+
lambda envelope: {"fallback": True},
|
|
120
|
+
request,
|
|
121
|
+
RemoteOptions("http://127.0.0.1:8789/v1/guard"),
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`RemoteResponse` retains the original status/headers and streaming `body`.
|
|
126
|
+
Any 5xx/refusal/timeout/reset invokes the original callable once and emits one
|
|
127
|
+
bypass. Writes/unknown operations require the same upstream idempotency key in
|
|
128
|
+
the envelope and fallback. `guard_remote_async` runs the blocking API in a
|
|
129
|
+
worker thread for a synchronous fallback callable.
|
|
130
|
+
|
|
131
|
+
Opt-in machine-identity helpers stay credential-free in embedded mode; they do
|
|
132
|
+
not enable a hosted identity service by themselves. Sibling Node package:
|
|
133
|
+
`agindow`.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# agindow (Python)
|
|
2
|
+
|
|
3
|
+
API drift firewall for AI agents on Python 3.11+ — repair drift in-flight, prove
|
|
4
|
+
the write was correct. **Pre-alpha** on PyPI as `agindow`. Loads the **identical
|
|
5
|
+
WASM bytes** built for `agindow` through Wasmtime. Python provides
|
|
6
|
+
callable/configuration/availability glue — not a second drift engine.
|
|
7
|
+
|
|
8
|
+
The default engine detects nothing until you configure protection. Statistical
|
|
9
|
+
windows require explicit local baseline/live selections.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install agindow
|
|
15
|
+
# or: uv add agindow
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The wheel includes the prebuilt WASM guest. You do **not** need Rust, Node, or a
|
|
19
|
+
monorepo checkout to use the SDK.
|
|
20
|
+
|
|
21
|
+
## Decorators, async and contexts
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from agindow import Agindow, guard
|
|
25
|
+
|
|
26
|
+
@guard(mode="repair", tool="customers.create", operation="write")
|
|
27
|
+
def create_customer(email: str) -> dict[str, str]:
|
|
28
|
+
return {"email": email}
|
|
29
|
+
|
|
30
|
+
sdk = Agindow(mode="observe")
|
|
31
|
+
|
|
32
|
+
@sdk.guard(tool="customers.read", operation="read")
|
|
33
|
+
async def read_customer() -> dict[str, str]:
|
|
34
|
+
return {"id": "fixture"}
|
|
35
|
+
|
|
36
|
+
with sdk.context(mode="strict"):
|
|
37
|
+
# Only calls through this SDK's guards use the scoped configuration.
|
|
38
|
+
pass
|
|
39
|
+
# `async with sdk.context(...)` is supported as well.
|
|
40
|
+
sdk.close()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Context managers scope guarded calls; they cannot intercept arbitrary Python
|
|
44
|
+
statements. Overrides use ContextVar, nest and remain isolated across async
|
|
45
|
+
tasks. Each call freezes configuration until completion. `configure(mode="repair")`
|
|
46
|
+
changes future calls. `sdk.ready` is a synchronous boolean after local loading
|
|
47
|
+
(unlike Node’s startup Promise); `sdk.load_error` retains a loading failure.
|
|
48
|
+
Loading failures and retired guests preserve upstream results and emit one
|
|
49
|
+
bypass per call. `close()` is safe for shutdown; subsequent calls bypass.
|
|
50
|
+
|
|
51
|
+
The wrapper preserves `__name__`, documentation, annotations, signatures,
|
|
52
|
+
bound receivers and arguments. ParamSpec retains Pydantic model types without
|
|
53
|
+
a mandatory Pydantic dependency. Model results retain their original identity;
|
|
54
|
+
only a detached `model_dump(mode="json")` projection enters inspection.
|
|
55
|
+
|
|
56
|
+
## Configuration and feedback
|
|
57
|
+
|
|
58
|
+
Supported fields (snake_case): `mode`, `fail_closed`, `api_key`, `endpoint`,
|
|
59
|
+
`allowed_tools` (`"*"` or a tuple), `deny_tools`, `buffer` and `on_event`.
|
|
60
|
+
Resolution: explicit keywords > environment > nearest JSON `.agindowrc` >
|
|
61
|
+
defaults. Shared env vars match Node (`AGINDOW_MODE`, `AGINDOW_KEY`,
|
|
62
|
+
`AGINDOW_ENDPOINT`, `AGINDOW_BUFFER`, `AGINDOW_FAIL_CLOSED`). Invalid explicit
|
|
63
|
+
or environment values raise `AgindowSetupError` before a call.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from agindow import AgindowDriftError
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
create_customer("fixture@example.test")
|
|
70
|
+
except AgindowDriftError as error:
|
|
71
|
+
print(error.code, error.tool, error.drift_class, error.drift_id)
|
|
72
|
+
print(error.hint, error.audit_url)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Request halts dispatch zero times. Response halts retain `error.outcome` and
|
|
76
|
+
warn against blind replay. Upstream exceptions survive as `error.__cause__`.
|
|
77
|
+
Missing audit IDs/URLs remain empty rather than fabricated.
|
|
78
|
+
|
|
79
|
+
`on(type, handler)` returns an unsubscribe callback; `recent()` returns an
|
|
80
|
+
immutable tuple of retained events. `buffer=0` disables retention. This is local
|
|
81
|
+
telemetry, not hosted audit delivery.
|
|
82
|
+
|
|
83
|
+
## Shared-core validation and limits
|
|
84
|
+
|
|
85
|
+
Parity fixtures run both public wrappers against the same WASM guest. The
|
|
86
|
+
paired local agent-loop benchmark gates added p50 <100 µs on the default
|
|
87
|
+
NullEngine only (excludes model/network/import/statistical work).
|
|
88
|
+
|
|
89
|
+
Python `wrap` currently accepts callables. Node-specific tool/client/HTTP
|
|
90
|
+
adapters, Nango codegen, OTel spans, report CLI and remote configuration/audit
|
|
91
|
+
transports are outside this package. No Python framework adapter or streaming
|
|
92
|
+
qualification is claimed. Inspection is bounded to detached JSON projections.
|
|
93
|
+
|
|
94
|
+
## Remote fail-open API
|
|
95
|
+
|
|
96
|
+
Local decorators stay offline. Remote execution is a separate HTTP API using
|
|
97
|
+
stdlib HTTP transport; it never redirects or retries through AGINDOW:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from agindow import RemoteEnvelope, RemoteOptions, guard_remote
|
|
101
|
+
|
|
102
|
+
request = RemoteEnvelope("vendor.read", "example", "read", {}, "observe")
|
|
103
|
+
result = guard_remote(
|
|
104
|
+
lambda envelope: {"fallback": True},
|
|
105
|
+
request,
|
|
106
|
+
RemoteOptions("http://127.0.0.1:8789/v1/guard"),
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`RemoteResponse` retains the original status/headers and streaming `body`.
|
|
111
|
+
Any 5xx/refusal/timeout/reset invokes the original callable once and emits one
|
|
112
|
+
bypass. Writes/unknown operations require the same upstream idempotency key in
|
|
113
|
+
the envelope and fallback. `guard_remote_async` runs the blocking API in a
|
|
114
|
+
worker thread for a synchronous fallback callable.
|
|
115
|
+
|
|
116
|
+
Opt-in machine-identity helpers stay credential-free in embedded mode; they do
|
|
117
|
+
not enable a hosted identity service by themselves. Sibling Node package:
|
|
118
|
+
`agindow`.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Fictional local evidence: no credentials, vendor calls or production claims."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from agindow import Agindow, AgindowDriftError
|
|
6
|
+
|
|
7
|
+
selection: dict[str, object] = {
|
|
8
|
+
"tenant": "fixture", "connection": "fixture", "vendor": "fixture", "operation": "op", "segment": "fixture",
|
|
9
|
+
"fields": [{"side": "request", "path": "/value", "baseline": ['{"value":1}'] * 128,
|
|
10
|
+
"live": ['{"value":100}'] * 128, "enumeration": True}],
|
|
11
|
+
}
|
|
12
|
+
sdk = Agindow(mode="repair", selection=selection)
|
|
13
|
+
if not sdk.ready:
|
|
14
|
+
raise RuntimeError(f"shared guest unavailable: {sdk.load_error}")
|
|
15
|
+
calls = 0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@sdk.guard(tool="op", operation="write")
|
|
19
|
+
def upstream(value: dict[str, int]) -> dict[str, int]:
|
|
20
|
+
global calls
|
|
21
|
+
calls += 1
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
original = {"value": 100}
|
|
26
|
+
try:
|
|
27
|
+
upstream(original)
|
|
28
|
+
raise AssertionError("fixture should halt before dispatch")
|
|
29
|
+
except AgindowDriftError as error:
|
|
30
|
+
print(json.dumps({"code": error.code, "phase": error.phase, "dispatches": calls}))
|
|
31
|
+
with sdk.context(mode="observe"):
|
|
32
|
+
assert upstream(original) is original
|
|
33
|
+
print(json.dumps({"observe_preserved_reference": True, "total_dispatches": calls}))
|
|
34
|
+
sdk.close()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "agindow"
|
|
3
|
+
version = "0.1.0a0"
|
|
4
|
+
description = "API drift firewall for AI agents on Python (Rust/WASM)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
keywords = [
|
|
9
|
+
"ai",
|
|
10
|
+
"agents",
|
|
11
|
+
"api",
|
|
12
|
+
"drift",
|
|
13
|
+
"firewall",
|
|
14
|
+
"llm",
|
|
15
|
+
"wasm",
|
|
16
|
+
"guard",
|
|
17
|
+
"sdk",
|
|
18
|
+
"observability",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"wasmtime==46.0.1",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/agindow/sdk"
|
|
26
|
+
Repository = "https://github.com/agindow/sdk"
|
|
27
|
+
Issues = "https://github.com/agindow/sdk/issues"
|
|
28
|
+
|
|
29
|
+
[build-system]
|
|
30
|
+
requires = ["hatchling==1.32.4"]
|
|
31
|
+
build-backend = "hatchling.build"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"hatchling>=1.27,<2",
|
|
36
|
+
"mypy>=1.15,<2",
|
|
37
|
+
"pydantic>=2.11,<3",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/agindow"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
44
|
+
"src/agindow/_guest.wasm" = "agindow/_guest.wasm"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.sdist]
|
|
47
|
+
include = ["src", "tests", "scripts", "examples", "pyproject.toml", "uv.lock", "README.md", "LICENSE", "NOTICE"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist.force-include]
|
|
50
|
+
"src/agindow/_guest.wasm" = "src/agindow/_guest.wasm"
|
|
51
|
+
|
|
52
|
+
[tool.mypy]
|
|
53
|
+
python_version = "3.11"
|
|
54
|
+
strict = true
|
|
55
|
+
files = ["src", "tests", "scripts", "examples"]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Paired local default-engine agent loop; no model/vendor/network latency."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import math
|
|
6
|
+
import platform
|
|
7
|
+
import sys
|
|
8
|
+
from importlib.metadata import version
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from statistics import mean, pstdev
|
|
11
|
+
from time import perf_counter_ns
|
|
12
|
+
from typing import Callable
|
|
13
|
+
from agindow import Agindow
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def quantile(values: list[float], probability: float) -> float:
|
|
17
|
+
return sorted(values)[math.ceil(len(values) * probability) - 1]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def measure() -> dict[str, object]:
|
|
21
|
+
started = perf_counter_ns()
|
|
22
|
+
sdk = Agindow()
|
|
23
|
+
load_us = (perf_counter_ns() - started) / 1000
|
|
24
|
+
if not sdk.ready:
|
|
25
|
+
raise RuntimeError(f"guest failed to load: {sdk.load_error}")
|
|
26
|
+
payload = {"result": "x" * 849}
|
|
27
|
+
tools = {"lookup": lambda: payload, "verify": lambda: payload}
|
|
28
|
+
guarded = {name: sdk.guard(fn) for name, fn in tools.items()}
|
|
29
|
+
steps = 0
|
|
30
|
+
observation = payload
|
|
31
|
+
|
|
32
|
+
def step(target: dict[str, Callable[[], dict[str, str]]]) -> None:
|
|
33
|
+
nonlocal observation, steps
|
|
34
|
+
action = "lookup" if (len(observation["result"]) + steps) % 2 == 0 else "verify"
|
|
35
|
+
observation = target[action]()
|
|
36
|
+
if observation is not payload:
|
|
37
|
+
raise RuntimeError("outcome identity lost")
|
|
38
|
+
steps += 1
|
|
39
|
+
|
|
40
|
+
for _ in range(1000):
|
|
41
|
+
step(tools)
|
|
42
|
+
step(guarded)
|
|
43
|
+
raw: dict[str, list[float]] = {"guarded": [], "unguarded": [], "added": []}
|
|
44
|
+
for index in range(5000):
|
|
45
|
+
sample: dict[str, float] = {}
|
|
46
|
+
for kind in (("guarded", "unguarded") if index % 2 == 0 else ("unguarded", "guarded")):
|
|
47
|
+
started = perf_counter_ns()
|
|
48
|
+
step(guarded if kind == "guarded" else tools)
|
|
49
|
+
sample[kind] = (perf_counter_ns() - started) / 1000
|
|
50
|
+
raw[kind].append(sample[kind])
|
|
51
|
+
raw["added"].append(sample["guarded"] - sample["unguarded"])
|
|
52
|
+
summary = {key: {"p50": quantile(values, .5), "p99": quantile(values, .99),
|
|
53
|
+
"mean": mean(values), "stddev": pstdev(values)} for key, values in raw.items()}
|
|
54
|
+
bypasses = sum(event.type == "bypass" for event in sdk.recent())
|
|
55
|
+
report: dict[str, object] = {"schema": "agindow.python-loop/1", "samples": 5000, "warmups": 1000,
|
|
56
|
+
"fixture": "local agent tool-selection/observation loop; NullEngine through the shared release WASM",
|
|
57
|
+
"estimator": "p50 of alternating paired guarded-minus-unguarded steps; nearest-rank quantiles",
|
|
58
|
+
"steps": steps, "payloadBytes": 862, "bypasses": bypasses, "loadUs": load_us, "summary": summary, "raw": raw,
|
|
59
|
+
"environment": {"python": sys.version, "wasmtime": version("wasmtime"), "platform": platform.platform(),
|
|
60
|
+
"arch": platform.machine(), "cpu": platform.processor()},
|
|
61
|
+
"exclusions": ["module import before load timer", "model inference", "vendor/network", "statistical paths (TI-53)"]}
|
|
62
|
+
output = Path(__file__).resolve().parents[4] / "target/python-loop/report.json"
|
|
63
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
64
|
+
output.write_text(json.dumps(report, indent=2) + "\n")
|
|
65
|
+
print(json.dumps({"addedUs": summary["added"], "loadUs": load_us, "report": str(output)}))
|
|
66
|
+
if summary["added"]["p50"] >= 100 or bypasses:
|
|
67
|
+
raise RuntimeError("Python default-engine loop budget failed")
|
|
68
|
+
return report
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
measure()
|