agent-tool-call-gate 0.1.0__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.
- agent_tool_call_gate-0.1.0/LICENSE +21 -0
- agent_tool_call_gate-0.1.0/PKG-INFO +126 -0
- agent_tool_call_gate-0.1.0/README.md +105 -0
- agent_tool_call_gate-0.1.0/agent_tool_call_gate.egg-info/PKG-INFO +126 -0
- agent_tool_call_gate-0.1.0/agent_tool_call_gate.egg-info/SOURCES.txt +33 -0
- agent_tool_call_gate-0.1.0/agent_tool_call_gate.egg-info/dependency_links.txt +1 -0
- agent_tool_call_gate-0.1.0/agent_tool_call_gate.egg-info/requires.txt +2 -0
- agent_tool_call_gate-0.1.0/agent_tool_call_gate.egg-info/top_level.txt +1 -0
- agent_tool_call_gate-0.1.0/agentgate/__init__.py +8 -0
- agent_tool_call_gate-0.1.0/agentgate/audit.py +274 -0
- agent_tool_call_gate-0.1.0/agentgate/gate.py +652 -0
- agent_tool_call_gate-0.1.0/agentgate/matching.py +42 -0
- agent_tool_call_gate-0.1.0/agentgate/models.py +29 -0
- agent_tool_call_gate-0.1.0/agentgate/normalize.py +80 -0
- agent_tool_call_gate-0.1.0/agentgate/policy.py +532 -0
- agent_tool_call_gate-0.1.0/agentgate/redact.py +118 -0
- agent_tool_call_gate-0.1.0/agentgate/risk.py +55 -0
- agent_tool_call_gate-0.1.0/agentgate/sql.py +192 -0
- agent_tool_call_gate-0.1.0/agentgate/taint.py +101 -0
- agent_tool_call_gate-0.1.0/pyproject.toml +28 -0
- agent_tool_call_gate-0.1.0/setup.cfg +4 -0
- agent_tool_call_gate-0.1.0/tests/test_attacks.py +99 -0
- agent_tool_call_gate-0.1.0/tests/test_audit.py +237 -0
- agent_tool_call_gate-0.1.0/tests/test_benchmark.py +247 -0
- agent_tool_call_gate-0.1.0/tests/test_benign.py +57 -0
- agent_tool_call_gate-0.1.0/tests/test_ci_workflow.py +14 -0
- agent_tool_call_gate-0.1.0/tests/test_demo.py +253 -0
- agent_tool_call_gate-0.1.0/tests/test_gate.py +330 -0
- agent_tool_call_gate-0.1.0/tests/test_latency.py +79 -0
- agent_tool_call_gate-0.1.0/tests/test_mcp.py +374 -0
- agent_tool_call_gate-0.1.0/tests/test_phase3.py +825 -0
- agent_tool_call_gate-0.1.0/tests/test_policy.py +317 -0
- agent_tool_call_gate-0.1.0/tests/test_redact.py +137 -0
- agent_tool_call_gate-0.1.0/tests/test_risk.py +93 -0
- agent_tool_call_gate-0.1.0/tests/test_round2b_regressions.py +258 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Waseem Mushtaq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-tool-call-gate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic policy enforcement for agent tool calls
|
|
5
|
+
Author-email: Waseem Mushtaq <waseemmushtaq045@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/waseem1302-x/agent-tool-call-gate
|
|
8
|
+
Project-URL: Source, https://github.com/waseem1302-x/agent-tool-call-gate
|
|
9
|
+
Project-URL: Issues, https://github.com/waseem1302-x/agent-tool-call-gate/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: PyYAML==6.0.4
|
|
19
|
+
Requires-Dist: jsonschema==4.26.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# agentgate
|
|
23
|
+
|
|
24
|
+
agentgate is a deterministic Python policy gate for agent tool calls. It checks
|
|
25
|
+
proposed calls before execution and records decisions in a hash-chained SQLite
|
|
26
|
+
audit log. It does not use a language model.
|
|
27
|
+
|
|
28
|
+
## Packaging
|
|
29
|
+
|
|
30
|
+
The install name is `agent-tool-call-gate` (`pip install agent-tool-call-gate`
|
|
31
|
+
after publication); the import name remains `agentgate`. The names differ
|
|
32
|
+
because `agentgate` is already taken on PyPI by an unrelated project. See
|
|
33
|
+
[docs/PYPI_NAME.md](docs/PYPI_NAME.md) for the naming decision.
|
|
34
|
+
The example below uses `policies/default.yaml` from the source checkout;
|
|
35
|
+
provide a policy file when using the installed wheel.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
from agentgate import Gate
|
|
40
|
+
|
|
41
|
+
gate = Gate(policy_path="policies/default.yaml", db_path="agentgate.db")
|
|
42
|
+
# After creating the file, report its actual result to this same gate instance.
|
|
43
|
+
read = gate.evaluate(tool="read_file", arguments={"path": "/home/agent/private/brief.txt"}, agent_id="session-1")
|
|
44
|
+
if read.verdict == "allow":
|
|
45
|
+
text = Path(read.checked_arguments["path"]).read_text(encoding="utf-8")
|
|
46
|
+
gate.observe(read.call_id, text)
|
|
47
|
+
decision = gate.evaluate(
|
|
48
|
+
tool="write_file",
|
|
49
|
+
arguments={"path": "/tmp/notes.txt", "content": "notes"}, agent_id="session-1",
|
|
50
|
+
)
|
|
51
|
+
if decision.verdict == "allow":
|
|
52
|
+
checked_arguments = decision.checked_arguments
|
|
53
|
+
# Execute the tool with exactly checked_arguments.
|
|
54
|
+
elif decision.verdict == "ask":
|
|
55
|
+
final_verdict = gate.resolve(decision.call_id, approved=True, approver="reviewer")
|
|
56
|
+
# Execute the checked arguments only if final_verdict is "allow".
|
|
57
|
+
|
|
58
|
+
head = gate.audit.head_hash # Store this outside the database.
|
|
59
|
+
assert gate.audit.verify(expected_head=head).ok
|
|
60
|
+
gate.close()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The caller must enforce the verdict and execute exactly the checked arguments.
|
|
64
|
+
`redacted_arguments` is suitable for logging; `checked_arguments` can contain
|
|
65
|
+
sensitive data and must not be logged. A denied call must not execute. Approval
|
|
66
|
+
rechecks both the policy file hash and the available budget. A pending request
|
|
67
|
+
can be resolved once. Budget counters belong to the lifetime of a gate.
|
|
68
|
+
|
|
69
|
+
## Data flow
|
|
70
|
+
|
|
71
|
+
`flow.restricted_prefixes` and `flow.restricted_tables` mark read sources as
|
|
72
|
+
restricted. Callers must report each successfully executed, allowed `read_file`
|
|
73
|
+
or `query_db` result as a string with `gate.observe(call_id, result)` on the same
|
|
74
|
+
gate instance. Use the same `agent_id` for subsequent calls in that session. The
|
|
75
|
+
gate stores bounded hashes, not the observed text. Matching copies in writes to
|
|
76
|
+
broader paths or tables and uploads are denied; matching email proposals ask for
|
|
77
|
+
approval. Fingerprints and duplicate call IDs persist in the audit database.
|
|
78
|
+
After reopening, stored taint still enforces, but pre-restart reads cannot be
|
|
79
|
+
observed or re-observed (`ValueError`); pending approvals and budgets do not
|
|
80
|
+
survive reopening.
|
|
81
|
+
|
|
82
|
+
The included stdio MCP server reports its own successful allowed reads to its
|
|
83
|
+
gate automatically, without exposing an observation tool to clients. See the
|
|
84
|
+
[MCP instructions](mcp_server/README.md).
|
|
85
|
+
|
|
86
|
+
This is bounded exact-fragment tracking, not semantic understanding: it misses
|
|
87
|
+
paraphrases, base64, fragments under 16 characters, unreported results and data
|
|
88
|
+
beyond its input and fingerprint limits. Re-observing a call adds fingerprints
|
|
89
|
+
to its existing taint without removing old ones, subject to the eviction cap.
|
|
90
|
+
|
|
91
|
+
The gate is not thread safe. Use one gate per thread and one writer per database
|
|
92
|
+
file. `close()` releases the writer lock. Audit write failures raise `AuditError`
|
|
93
|
+
instead of returning a verdict. Use a separately stored head hash when verifying
|
|
94
|
+
an audit log: someone who can rewrite the entire database can otherwise rewrite
|
|
95
|
+
the chain. A hash chain alone does not prevent that attack.
|
|
96
|
+
|
|
97
|
+
The gate only checks calls routed through it. Credential and PII detection uses
|
|
98
|
+
policy regexes, so encoded, split, and novel secrets can be missed. The SQL
|
|
99
|
+
classifier allows SELECT-shaped statements and rejects stacked statements and
|
|
100
|
+
SELECT INTO, but it is not a SQL sandbox: use a read-only database connection.
|
|
101
|
+
Paths are normalized, percent-decoded up to three times and rejected for NUL or
|
|
102
|
+
`..` components; this is lexical, not symlink resolution. The included MCP
|
|
103
|
+
server is local stdio only; HTTP, authentication and an approval endpoint are
|
|
104
|
+
not implemented. There is no LLM judge.
|
|
105
|
+
|
|
106
|
+
The frozen evaluation blocked 40 of 40 attacks and denied 0 of 40 benign calls;
|
|
107
|
+
9 benign calls required approval. A null-gate baseline allowed 37 of 40 attacks
|
|
108
|
+
(two disguised tool names and one NUL path still deny) and denied none of
|
|
109
|
+
the benign calls. Forty attacks are a small sample: observing no
|
|
110
|
+
permitted attack calls gives a one-sided 95 percent upper bound of about 7.2 percent
|
|
111
|
+
on their true allowance rate under an independent-samples assumption, not a
|
|
112
|
+
guarantee of zero risk. The evaluation checks verdicts; it does not execute the
|
|
113
|
+
attacks or measure data reaching a recipient.
|
|
114
|
+
The 40 cases are curated, not a random sample, so treat the bound as
|
|
115
|
+
illustrative. See [EVAL_RESULTS.md](EVAL_RESULTS.md)
|
|
116
|
+
for family results and latency. The separate [multi-turn benchmark](docs/BENCHMARK_RESULTS.md)
|
|
117
|
+
reports permitted goal calls in a scripted replay, not observed live leaks.
|
|
118
|
+
|
|
119
|
+
Run the checks in the project environment:
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
.venv/bin/python -m pytest -q -s
|
|
123
|
+
.venv/bin/ruff check agentgate tests
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
License: MIT (see LICENSE).
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# agentgate
|
|
2
|
+
|
|
3
|
+
agentgate is a deterministic Python policy gate for agent tool calls. It checks
|
|
4
|
+
proposed calls before execution and records decisions in a hash-chained SQLite
|
|
5
|
+
audit log. It does not use a language model.
|
|
6
|
+
|
|
7
|
+
## Packaging
|
|
8
|
+
|
|
9
|
+
The install name is `agent-tool-call-gate` (`pip install agent-tool-call-gate`
|
|
10
|
+
after publication); the import name remains `agentgate`. The names differ
|
|
11
|
+
because `agentgate` is already taken on PyPI by an unrelated project. See
|
|
12
|
+
[docs/PYPI_NAME.md](docs/PYPI_NAME.md) for the naming decision.
|
|
13
|
+
The example below uses `policies/default.yaml` from the source checkout;
|
|
14
|
+
provide a policy file when using the installed wheel.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from agentgate import Gate
|
|
19
|
+
|
|
20
|
+
gate = Gate(policy_path="policies/default.yaml", db_path="agentgate.db")
|
|
21
|
+
# After creating the file, report its actual result to this same gate instance.
|
|
22
|
+
read = gate.evaluate(tool="read_file", arguments={"path": "/home/agent/private/brief.txt"}, agent_id="session-1")
|
|
23
|
+
if read.verdict == "allow":
|
|
24
|
+
text = Path(read.checked_arguments["path"]).read_text(encoding="utf-8")
|
|
25
|
+
gate.observe(read.call_id, text)
|
|
26
|
+
decision = gate.evaluate(
|
|
27
|
+
tool="write_file",
|
|
28
|
+
arguments={"path": "/tmp/notes.txt", "content": "notes"}, agent_id="session-1",
|
|
29
|
+
)
|
|
30
|
+
if decision.verdict == "allow":
|
|
31
|
+
checked_arguments = decision.checked_arguments
|
|
32
|
+
# Execute the tool with exactly checked_arguments.
|
|
33
|
+
elif decision.verdict == "ask":
|
|
34
|
+
final_verdict = gate.resolve(decision.call_id, approved=True, approver="reviewer")
|
|
35
|
+
# Execute the checked arguments only if final_verdict is "allow".
|
|
36
|
+
|
|
37
|
+
head = gate.audit.head_hash # Store this outside the database.
|
|
38
|
+
assert gate.audit.verify(expected_head=head).ok
|
|
39
|
+
gate.close()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The caller must enforce the verdict and execute exactly the checked arguments.
|
|
43
|
+
`redacted_arguments` is suitable for logging; `checked_arguments` can contain
|
|
44
|
+
sensitive data and must not be logged. A denied call must not execute. Approval
|
|
45
|
+
rechecks both the policy file hash and the available budget. A pending request
|
|
46
|
+
can be resolved once. Budget counters belong to the lifetime of a gate.
|
|
47
|
+
|
|
48
|
+
## Data flow
|
|
49
|
+
|
|
50
|
+
`flow.restricted_prefixes` and `flow.restricted_tables` mark read sources as
|
|
51
|
+
restricted. Callers must report each successfully executed, allowed `read_file`
|
|
52
|
+
or `query_db` result as a string with `gate.observe(call_id, result)` on the same
|
|
53
|
+
gate instance. Use the same `agent_id` for subsequent calls in that session. The
|
|
54
|
+
gate stores bounded hashes, not the observed text. Matching copies in writes to
|
|
55
|
+
broader paths or tables and uploads are denied; matching email proposals ask for
|
|
56
|
+
approval. Fingerprints and duplicate call IDs persist in the audit database.
|
|
57
|
+
After reopening, stored taint still enforces, but pre-restart reads cannot be
|
|
58
|
+
observed or re-observed (`ValueError`); pending approvals and budgets do not
|
|
59
|
+
survive reopening.
|
|
60
|
+
|
|
61
|
+
The included stdio MCP server reports its own successful allowed reads to its
|
|
62
|
+
gate automatically, without exposing an observation tool to clients. See the
|
|
63
|
+
[MCP instructions](mcp_server/README.md).
|
|
64
|
+
|
|
65
|
+
This is bounded exact-fragment tracking, not semantic understanding: it misses
|
|
66
|
+
paraphrases, base64, fragments under 16 characters, unreported results and data
|
|
67
|
+
beyond its input and fingerprint limits. Re-observing a call adds fingerprints
|
|
68
|
+
to its existing taint without removing old ones, subject to the eviction cap.
|
|
69
|
+
|
|
70
|
+
The gate is not thread safe. Use one gate per thread and one writer per database
|
|
71
|
+
file. `close()` releases the writer lock. Audit write failures raise `AuditError`
|
|
72
|
+
instead of returning a verdict. Use a separately stored head hash when verifying
|
|
73
|
+
an audit log: someone who can rewrite the entire database can otherwise rewrite
|
|
74
|
+
the chain. A hash chain alone does not prevent that attack.
|
|
75
|
+
|
|
76
|
+
The gate only checks calls routed through it. Credential and PII detection uses
|
|
77
|
+
policy regexes, so encoded, split, and novel secrets can be missed. The SQL
|
|
78
|
+
classifier allows SELECT-shaped statements and rejects stacked statements and
|
|
79
|
+
SELECT INTO, but it is not a SQL sandbox: use a read-only database connection.
|
|
80
|
+
Paths are normalized, percent-decoded up to three times and rejected for NUL or
|
|
81
|
+
`..` components; this is lexical, not symlink resolution. The included MCP
|
|
82
|
+
server is local stdio only; HTTP, authentication and an approval endpoint are
|
|
83
|
+
not implemented. There is no LLM judge.
|
|
84
|
+
|
|
85
|
+
The frozen evaluation blocked 40 of 40 attacks and denied 0 of 40 benign calls;
|
|
86
|
+
9 benign calls required approval. A null-gate baseline allowed 37 of 40 attacks
|
|
87
|
+
(two disguised tool names and one NUL path still deny) and denied none of
|
|
88
|
+
the benign calls. Forty attacks are a small sample: observing no
|
|
89
|
+
permitted attack calls gives a one-sided 95 percent upper bound of about 7.2 percent
|
|
90
|
+
on their true allowance rate under an independent-samples assumption, not a
|
|
91
|
+
guarantee of zero risk. The evaluation checks verdicts; it does not execute the
|
|
92
|
+
attacks or measure data reaching a recipient.
|
|
93
|
+
The 40 cases are curated, not a random sample, so treat the bound as
|
|
94
|
+
illustrative. See [EVAL_RESULTS.md](EVAL_RESULTS.md)
|
|
95
|
+
for family results and latency. The separate [multi-turn benchmark](docs/BENCHMARK_RESULTS.md)
|
|
96
|
+
reports permitted goal calls in a scripted replay, not observed live leaks.
|
|
97
|
+
|
|
98
|
+
Run the checks in the project environment:
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
.venv/bin/python -m pytest -q -s
|
|
102
|
+
.venv/bin/ruff check agentgate tests
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
License: MIT (see LICENSE).
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-tool-call-gate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic policy enforcement for agent tool calls
|
|
5
|
+
Author-email: Waseem Mushtaq <waseemmushtaq045@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/waseem1302-x/agent-tool-call-gate
|
|
8
|
+
Project-URL: Source, https://github.com/waseem1302-x/agent-tool-call-gate
|
|
9
|
+
Project-URL: Issues, https://github.com/waseem1302-x/agent-tool-call-gate/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: PyYAML==6.0.4
|
|
19
|
+
Requires-Dist: jsonschema==4.26.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# agentgate
|
|
23
|
+
|
|
24
|
+
agentgate is a deterministic Python policy gate for agent tool calls. It checks
|
|
25
|
+
proposed calls before execution and records decisions in a hash-chained SQLite
|
|
26
|
+
audit log. It does not use a language model.
|
|
27
|
+
|
|
28
|
+
## Packaging
|
|
29
|
+
|
|
30
|
+
The install name is `agent-tool-call-gate` (`pip install agent-tool-call-gate`
|
|
31
|
+
after publication); the import name remains `agentgate`. The names differ
|
|
32
|
+
because `agentgate` is already taken on PyPI by an unrelated project. See
|
|
33
|
+
[docs/PYPI_NAME.md](docs/PYPI_NAME.md) for the naming decision.
|
|
34
|
+
The example below uses `policies/default.yaml` from the source checkout;
|
|
35
|
+
provide a policy file when using the installed wheel.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
from agentgate import Gate
|
|
40
|
+
|
|
41
|
+
gate = Gate(policy_path="policies/default.yaml", db_path="agentgate.db")
|
|
42
|
+
# After creating the file, report its actual result to this same gate instance.
|
|
43
|
+
read = gate.evaluate(tool="read_file", arguments={"path": "/home/agent/private/brief.txt"}, agent_id="session-1")
|
|
44
|
+
if read.verdict == "allow":
|
|
45
|
+
text = Path(read.checked_arguments["path"]).read_text(encoding="utf-8")
|
|
46
|
+
gate.observe(read.call_id, text)
|
|
47
|
+
decision = gate.evaluate(
|
|
48
|
+
tool="write_file",
|
|
49
|
+
arguments={"path": "/tmp/notes.txt", "content": "notes"}, agent_id="session-1",
|
|
50
|
+
)
|
|
51
|
+
if decision.verdict == "allow":
|
|
52
|
+
checked_arguments = decision.checked_arguments
|
|
53
|
+
# Execute the tool with exactly checked_arguments.
|
|
54
|
+
elif decision.verdict == "ask":
|
|
55
|
+
final_verdict = gate.resolve(decision.call_id, approved=True, approver="reviewer")
|
|
56
|
+
# Execute the checked arguments only if final_verdict is "allow".
|
|
57
|
+
|
|
58
|
+
head = gate.audit.head_hash # Store this outside the database.
|
|
59
|
+
assert gate.audit.verify(expected_head=head).ok
|
|
60
|
+
gate.close()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The caller must enforce the verdict and execute exactly the checked arguments.
|
|
64
|
+
`redacted_arguments` is suitable for logging; `checked_arguments` can contain
|
|
65
|
+
sensitive data and must not be logged. A denied call must not execute. Approval
|
|
66
|
+
rechecks both the policy file hash and the available budget. A pending request
|
|
67
|
+
can be resolved once. Budget counters belong to the lifetime of a gate.
|
|
68
|
+
|
|
69
|
+
## Data flow
|
|
70
|
+
|
|
71
|
+
`flow.restricted_prefixes` and `flow.restricted_tables` mark read sources as
|
|
72
|
+
restricted. Callers must report each successfully executed, allowed `read_file`
|
|
73
|
+
or `query_db` result as a string with `gate.observe(call_id, result)` on the same
|
|
74
|
+
gate instance. Use the same `agent_id` for subsequent calls in that session. The
|
|
75
|
+
gate stores bounded hashes, not the observed text. Matching copies in writes to
|
|
76
|
+
broader paths or tables and uploads are denied; matching email proposals ask for
|
|
77
|
+
approval. Fingerprints and duplicate call IDs persist in the audit database.
|
|
78
|
+
After reopening, stored taint still enforces, but pre-restart reads cannot be
|
|
79
|
+
observed or re-observed (`ValueError`); pending approvals and budgets do not
|
|
80
|
+
survive reopening.
|
|
81
|
+
|
|
82
|
+
The included stdio MCP server reports its own successful allowed reads to its
|
|
83
|
+
gate automatically, without exposing an observation tool to clients. See the
|
|
84
|
+
[MCP instructions](mcp_server/README.md).
|
|
85
|
+
|
|
86
|
+
This is bounded exact-fragment tracking, not semantic understanding: it misses
|
|
87
|
+
paraphrases, base64, fragments under 16 characters, unreported results and data
|
|
88
|
+
beyond its input and fingerprint limits. Re-observing a call adds fingerprints
|
|
89
|
+
to its existing taint without removing old ones, subject to the eviction cap.
|
|
90
|
+
|
|
91
|
+
The gate is not thread safe. Use one gate per thread and one writer per database
|
|
92
|
+
file. `close()` releases the writer lock. Audit write failures raise `AuditError`
|
|
93
|
+
instead of returning a verdict. Use a separately stored head hash when verifying
|
|
94
|
+
an audit log: someone who can rewrite the entire database can otherwise rewrite
|
|
95
|
+
the chain. A hash chain alone does not prevent that attack.
|
|
96
|
+
|
|
97
|
+
The gate only checks calls routed through it. Credential and PII detection uses
|
|
98
|
+
policy regexes, so encoded, split, and novel secrets can be missed. The SQL
|
|
99
|
+
classifier allows SELECT-shaped statements and rejects stacked statements and
|
|
100
|
+
SELECT INTO, but it is not a SQL sandbox: use a read-only database connection.
|
|
101
|
+
Paths are normalized, percent-decoded up to three times and rejected for NUL or
|
|
102
|
+
`..` components; this is lexical, not symlink resolution. The included MCP
|
|
103
|
+
server is local stdio only; HTTP, authentication and an approval endpoint are
|
|
104
|
+
not implemented. There is no LLM judge.
|
|
105
|
+
|
|
106
|
+
The frozen evaluation blocked 40 of 40 attacks and denied 0 of 40 benign calls;
|
|
107
|
+
9 benign calls required approval. A null-gate baseline allowed 37 of 40 attacks
|
|
108
|
+
(two disguised tool names and one NUL path still deny) and denied none of
|
|
109
|
+
the benign calls. Forty attacks are a small sample: observing no
|
|
110
|
+
permitted attack calls gives a one-sided 95 percent upper bound of about 7.2 percent
|
|
111
|
+
on their true allowance rate under an independent-samples assumption, not a
|
|
112
|
+
guarantee of zero risk. The evaluation checks verdicts; it does not execute the
|
|
113
|
+
attacks or measure data reaching a recipient.
|
|
114
|
+
The 40 cases are curated, not a random sample, so treat the bound as
|
|
115
|
+
illustrative. See [EVAL_RESULTS.md](EVAL_RESULTS.md)
|
|
116
|
+
for family results and latency. The separate [multi-turn benchmark](docs/BENCHMARK_RESULTS.md)
|
|
117
|
+
reports permitted goal calls in a scripted replay, not observed live leaks.
|
|
118
|
+
|
|
119
|
+
Run the checks in the project environment:
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
.venv/bin/python -m pytest -q -s
|
|
123
|
+
.venv/bin/ruff check agentgate tests
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
License: MIT (see LICENSE).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
agent_tool_call_gate.egg-info/PKG-INFO
|
|
5
|
+
agent_tool_call_gate.egg-info/SOURCES.txt
|
|
6
|
+
agent_tool_call_gate.egg-info/dependency_links.txt
|
|
7
|
+
agent_tool_call_gate.egg-info/requires.txt
|
|
8
|
+
agent_tool_call_gate.egg-info/top_level.txt
|
|
9
|
+
agentgate/__init__.py
|
|
10
|
+
agentgate/audit.py
|
|
11
|
+
agentgate/gate.py
|
|
12
|
+
agentgate/matching.py
|
|
13
|
+
agentgate/models.py
|
|
14
|
+
agentgate/normalize.py
|
|
15
|
+
agentgate/policy.py
|
|
16
|
+
agentgate/redact.py
|
|
17
|
+
agentgate/risk.py
|
|
18
|
+
agentgate/sql.py
|
|
19
|
+
agentgate/taint.py
|
|
20
|
+
tests/test_attacks.py
|
|
21
|
+
tests/test_audit.py
|
|
22
|
+
tests/test_benchmark.py
|
|
23
|
+
tests/test_benign.py
|
|
24
|
+
tests/test_ci_workflow.py
|
|
25
|
+
tests/test_demo.py
|
|
26
|
+
tests/test_gate.py
|
|
27
|
+
tests/test_latency.py
|
|
28
|
+
tests/test_mcp.py
|
|
29
|
+
tests/test_phase3.py
|
|
30
|
+
tests/test_policy.py
|
|
31
|
+
tests/test_redact.py
|
|
32
|
+
tests/test_risk.py
|
|
33
|
+
tests/test_round2b_regressions.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
agentgate
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Public API for deterministic agent tool-call policy enforcement."""
|
|
2
|
+
|
|
3
|
+
from .audit import AuditError
|
|
4
|
+
from .gate import Gate
|
|
5
|
+
from .models import Decision, ToolCall
|
|
6
|
+
from .policy import Policy, PolicyError
|
|
7
|
+
|
|
8
|
+
__all__ = ["AuditError", "Decision", "Gate", "Policy", "PolicyError", "ToolCall"]
|