tollgate 1.0.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.
Files changed (58) hide show
  1. tollgate-1.0.0/.claude/settings.local.json +16 -0
  2. tollgate-1.0.0/.gitignore +12 -0
  3. tollgate-1.0.0/CHANGELOG.md +19 -0
  4. tollgate-1.0.0/COMPARISON.md +125 -0
  5. tollgate-1.0.0/CONTRIBUTING.md +23 -0
  6. tollgate-1.0.0/LICENSE +176 -0
  7. tollgate-1.0.0/Makefile +22 -0
  8. tollgate-1.0.0/PKG-INFO +98 -0
  9. tollgate-1.0.0/QUICKSTART.md +133 -0
  10. tollgate-1.0.0/README.md +73 -0
  11. tollgate-1.0.0/SECURITY.md +29 -0
  12. tollgate-1.0.0/examples/mcp_minimal/audit.jsonl +6 -0
  13. tollgate-1.0.0/examples/mcp_minimal/demo.py +78 -0
  14. tollgate-1.0.0/examples/mcp_minimal/manifest.yaml +8 -0
  15. tollgate-1.0.0/examples/mcp_minimal/policy.yaml +8 -0
  16. tollgate-1.0.0/examples/mock_tickets/README.md +24 -0
  17. tollgate-1.0.0/examples/mock_tickets/agent.py +93 -0
  18. tollgate-1.0.0/examples/mock_tickets/demo.py +48 -0
  19. tollgate-1.0.0/examples/mock_tickets/manifest.yaml +8 -0
  20. tollgate-1.0.0/examples/mock_tickets/tickets.json +26 -0
  21. tollgate-1.0.0/examples/mock_tickets/tools.py +47 -0
  22. tollgate-1.0.0/examples/strands_minimal/audit.jsonl +4 -0
  23. tollgate-1.0.0/examples/strands_minimal/demo.py +80 -0
  24. tollgate-1.0.0/examples/strands_minimal/manifest.yaml +9 -0
  25. tollgate-1.0.0/examples/strands_minimal/policy.yaml +8 -0
  26. tollgate-1.0.0/policies/default.yaml +27 -0
  27. tollgate-1.0.0/pyproject.toml +51 -0
  28. tollgate-1.0.0/specs/audit_event.schema.json +18 -0
  29. tollgate-1.0.0/specs/decision.schema.json +13 -0
  30. tollgate-1.0.0/specs/identity.schema.json +12 -0
  31. tollgate-1.0.0/specs/intent.schema.json +12 -0
  32. tollgate-1.0.0/specs/tool_request.schema.json +15 -0
  33. tollgate-1.0.0/src/tollgate/__init__.py +66 -0
  34. tollgate-1.0.0/src/tollgate/approvals.py +227 -0
  35. tollgate-1.0.0/src/tollgate/audit.py +47 -0
  36. tollgate-1.0.0/src/tollgate/exceptions.py +28 -0
  37. tollgate-1.0.0/src/tollgate/helpers.py +72 -0
  38. tollgate-1.0.0/src/tollgate/integrations/__init__.py +0 -0
  39. tollgate-1.0.0/src/tollgate/integrations/mcp.py +58 -0
  40. tollgate-1.0.0/src/tollgate/integrations/strands.py +89 -0
  41. tollgate-1.0.0/src/tollgate/interceptors/__init__.py +12 -0
  42. tollgate-1.0.0/src/tollgate/interceptors/base.py +41 -0
  43. tollgate-1.0.0/src/tollgate/interceptors/langchain.py +91 -0
  44. tollgate-1.0.0/src/tollgate/interceptors/openai.py +87 -0
  45. tollgate-1.0.0/src/tollgate/policy.py +152 -0
  46. tollgate-1.0.0/src/tollgate/registry.py +58 -0
  47. tollgate-1.0.0/src/tollgate/tower.py +224 -0
  48. tollgate-1.0.0/src/tollgate/types.py +124 -0
  49. tollgate-1.0.0/tests/test_adapters_v1.py +33 -0
  50. tollgate-1.0.0/tests/test_audit_integrity_v1.py +57 -0
  51. tollgate-1.0.0/tests/test_deferred_v1.py +69 -0
  52. tollgate-1.0.0/tests/test_helpers_v1.py +63 -0
  53. tollgate-1.0.0/tests/test_integrations_v1.py +85 -0
  54. tollgate-1.0.0/tests/test_policy_v1.py +82 -0
  55. tollgate-1.0.0/tests/test_registry_v1.py +24 -0
  56. tollgate-1.0.0/tests/test_security_v1.py +78 -0
  57. tollgate-1.0.0/tests/test_tower_v1.py +141 -0
  58. tollgate-1.0.0/tests/test_v1_integrations.py +96 -0
@@ -0,0 +1,16 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(tree:*)",
5
+ "Bash(python -m pytest -v)",
6
+ "Bash(python3 -m pytest:*)",
7
+ "Bash(pip3 install:*)",
8
+ "Bash(.venv/bin/python -m pytest:*)",
9
+ "Bash(.venv/bin/ruff check:*)",
10
+ "Bash(.venv/bin/ruff format:*)",
11
+ "Bash(git init:*)",
12
+ "Bash(gh auth status:*)",
13
+ "Bash(.venv/bin/python:*)"
14
+ ]
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ examples/mock_tickets/audit.jsonl
12
+ examples/mock_tickets/tickets.json.bak
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-01-27
9
+ ### Added
10
+ - **Interception-First Architecture**: Added `TollgateInterceptor` and framework adapters for LangChain and OpenAI.
11
+ - **Trusted Tool Registry**: Introduced `ToolRegistry` to enforce developer-controlled tool metadata.
12
+ - **Async-First Execution**: The `ControlTower` now natively supports asynchronous tool execution and approvals.
13
+ - **Approval Integrity**: Added `request_hash` binding and `ApprovalStore` for secure, persistent async approvals.
14
+ - **Safe Defaults**: Policies now enforce `DENY` for unknown effects and require trusted attributes for `ALLOW`.
15
+ - **Structured Audit v2**: Enhanced audit logs with `correlation_id`, `request_hash`, and manifest versions.
16
+
17
+ ## [0.0.1] - 2026-01-25
18
+ ### Added
19
+ - Initial v0 release of `tollgate`.
@@ -0,0 +1,125 @@
1
+ # Tollgate: Integration Effort Comparison 📊
2
+
3
+ This guide demonstrates the minimal changes required to integrate `tollgate` into your existing AI agent workflows.
4
+
5
+ ---
6
+
7
+ ## 🔹 Scenario 1: Plain Python Tools
8
+ **Effort:** ~5 lines of setup + 1 wrapper call.
9
+
10
+ ### ❌ Before Tollgate
11
+ Directly calling a tool function with no gating.
12
+
13
+ ```python
14
+ def delete_database(db_id: str):
15
+ print(f"Deleting database {db_id}...")
16
+
17
+ # No protection - if the agent decides to call this, it happens.
18
+ delete_database("prod-db-01")
19
+ ```
20
+
21
+ ### ✅ After Tollgate
22
+ Wrapping the tool to ensure it passes through the Control Tower.
23
+
24
+ ```python
25
+ from tollgate import ControlTower, ToolRegistry, YamlPolicyEvaluator, CliApprover, JsonlAuditSink
26
+ from tollgate.helpers import wrap_tool
27
+
28
+ # 1. Setup (One-time)
29
+ registry = ToolRegistry("manifest.yaml")
30
+ tower = ControlTower(
31
+ policy=YamlPolicyEvaluator("policy.yaml"),
32
+ approver=CliApprover(),
33
+ audit=JsonlAuditSink("audit.jsonl")
34
+ )
35
+
36
+ # 2. Wrap tool (Minimal change)
37
+ guarded_delete = wrap_tool(tower, delete_database,
38
+ tool="db_admin", action="delete",
39
+ resource_type="database", effect="delete")
40
+
41
+ # 3. Secure execution
42
+ guarded_delete(agent_ctx, intent, db_id="prod-db-01")
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 🔹 Scenario 2: LangChain Integration
48
+ **Effort:** ~5 lines of setup + 1 line for `guard_tools`.
49
+
50
+ ### ❌ Before Tollgate
51
+ Ungated tools passed directly to an agent.
52
+
53
+ ```python
54
+ from langchain.agents import initialize_agent
55
+
56
+ tools = [SearchTool(), CalculatorTool()]
57
+ agent = initialize_agent(tools, llm, agent="zero-shot-react-description")
58
+
59
+ # Agent calls tools freely
60
+ agent.run("Calculate the GDP of France.")
61
+ ```
62
+
63
+ ### ✅ After Tollgate
64
+ Interception at the tool boundary.
65
+
66
+ ```python
67
+ from tollgate.interceptors.langchain import guard_tools
68
+
69
+ # 1. Setup Tollgate (as shown in Scenario 1)
70
+ # ... tower/registry setup ...
71
+
72
+ # 2. Guard tools (1 line change)
73
+ guarded_tools = guard_tools(tools, tower, registry)
74
+
75
+ # 3. Secure execution
76
+ agent = initialize_agent(guarded_tools, llm, ...)
77
+ # Tools now require agent_ctx and intent to proceed (or they default to DENY)
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 🔹 Scenario 3: MCP (Model Context Protocol)
83
+ **Effort:** Swapping the client class.
84
+
85
+ ### ❌ Before Tollgate
86
+ Direct usage of an MCP client.
87
+
88
+ ```python
89
+ from mcp_client import Client
90
+
91
+ client = Client(server_url="...")
92
+ # Ungated call
93
+ await client.call_tool("read_file", {"path": "secrets.txt"})
94
+ ```
95
+
96
+ ### ✅ After Tollgate
97
+ Using the `TollgateMCPClient` wrapper.
98
+
99
+ ```python
100
+ from tollgate.integrations.mcp import TollgateMCPClient
101
+
102
+ # 1. Setup Tollgate (as shown in Scenario 1)
103
+ # ... tower/registry setup ...
104
+
105
+ # 2. Swap Client (1 line change)
106
+ gated_client = TollgateMCPClient(base_client, server_name="fs", tower=tower, registry=registry)
107
+
108
+ # 3. Secure execution
109
+ await gated_client.call_tool("read_file", {"path": "secrets.txt"}, ctx, intent)
110
+ ```
111
+
112
+ ---
113
+
114
+ ## 📈 Integration Effort Summary
115
+
116
+ | Feature | Effort | Lines of Code Added |
117
+ | :--- | :--- | :--- |
118
+ | **Initial Setup** | Minimal | ~5-8 lines |
119
+ | **Tool Wrapping** | Near-Zero | 1 line per toolset |
120
+ | **In-Loop Change**| Zero | None (Enforcement is at the boundary) |
121
+
122
+ ### Why use Tollgate?
123
+ 1. **Separation of Concerns**: Your agent logic stays clean; security is handled at the boundary.
124
+ 2. **Deterministic Safety**: No more "hallucinated" tool calls causing real-world damage.
125
+ 3. **Audit Readiness**: Instant, structured logs for compliance and debugging.
@@ -0,0 +1,23 @@
1
+ # Contributing to tollgate
2
+
3
+ We welcome contributions! Please follow these basic guidelines:
4
+
5
+ 1. **Fork and Clone**: Fork the repo and clone it locally.
6
+ 2. **Setup**: Run `make install` to set up your environment.
7
+ 3. **Tests**: Ensure tests pass by running `make test`.
8
+ 4. **Linting**: We use `ruff`. Run `make lint` and `make format` before submitting.
9
+ 5. **PRs**: Keep PRs focused and include tests for new functionality.
10
+
11
+ ## Development Workflow
12
+
13
+ ```bash
14
+ # Install dependencies
15
+ make install
16
+
17
+ # Run tests
18
+ make test
19
+
20
+ # Lint and format
21
+ make lint
22
+ make format
23
+ ```
tollgate-1.0.0/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,22 @@
1
+ .PHONY: install test lint format build publish-test publish
2
+
3
+ install:
4
+ pip install -e ".[dev]"
5
+
6
+ test:
7
+ pytest
8
+
9
+ lint:
10
+ ruff check .
11
+
12
+ format:
13
+ ruff format .
14
+
15
+ build:
16
+ python -m build
17
+
18
+ publish-test:
19
+ python -m twine upload --repository testpypi dist/*
20
+
21
+ publish:
22
+ python -m twine upload dist/*
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: tollgate
3
+ Version: 1.0.0
4
+ Summary: Runtime enforcement layer for AI agent tool calls using Identity + Intent + Policy
5
+ Author: Tollgate Maintainers
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Keywords: agents,ai,enforcement,llm,policy,security
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pyyaml>=6.0.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: build>=1.0.0; extra == 'dev'
20
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
21
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
22
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
23
+ Requires-Dist: twine>=4.0.0; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # tollgate 🚪
27
+
28
+ Runtime enforcement layer for AI agent tool calls using **Identity + Intent + Policy**.
29
+
30
+ `tollgate` provides a deterministic safety boundary for AI agents. It ensures every tool call is validated against a policy before execution, with support for async human-in-the-loop approvals, framework interception (MCP, Strands, LangChain, OpenAI), and structured audit logging.
31
+
32
+ **[🚀 Quickstart Guide](./QUICKSTART.md) | [📊 Integration Comparison](./COMPARISON.md)**
33
+
34
+ ```mermaid
35
+ graph TD
36
+ A[AI Agent] -->|Tool Call| B(Tollgate Interceptor)
37
+ B --> C{Policy + Registry}
38
+ C -->|ALLOW| D[Execute Tool]
39
+ C -->|DENY| E[Block & Audit]
40
+ C -->|ASK| F{Human Approval}
41
+ F -->|Approved| D
42
+ F -->|Denied| E
43
+ D --> G[Audit Log]
44
+ E --> G
45
+ ```
46
+
47
+ ## ✨ v1 Core Principles
48
+
49
+ 1. **Interception-First**: Enforcement happens at the tool execution boundary via adapters.
50
+ 2. **Safe Defaults**: Any unknown tool effect or resource defaults to **DENY**.
51
+ 3. **Trust Model**: Tool metadata is trusted only if it comes from a developer-controlled **Tool Registry**.
52
+ 4. **Approval Integrity**: Approvals are bound to a request hash and correlation ID with replay protection.
53
+ 5. **Async-First**: Native support for asynchronous agent loops and non-blocking approvals.
54
+ 6. **Audit Integrity**: Every decision, approval, and outcome is recorded with full cryptographic context.
55
+
56
+ ## 🚀 v1 Integrations
57
+
58
+ ### MCP (Model Context Protocol)
59
+ Wrap an MCP client to gate all tool calls:
60
+ ```python
61
+ from tollgate import ControlTower, ToolRegistry
62
+ from tollgate.integrations.mcp import TollgateMCPClient
63
+
64
+ registry = ToolRegistry("manifest.yaml")
65
+ tower = ControlTower(...)
66
+ client = TollgateMCPClient(base_client, server_name="my_server", tower=tower, registry=registry)
67
+
68
+ # Calls are now gated!
69
+ await client.call_tool("read_data", {"id": 1}, agent_ctx=ctx, intent=intent)
70
+ ```
71
+
72
+ ### Strands Agents
73
+ Gate Strands tools with minimal friction:
74
+ ```python
75
+ from tollgate.integrations.strands import guard_tools
76
+
77
+ guarded = guard_tools(my_strands_tools, tower, registry)
78
+
79
+ # Use guarded tools in your agent
80
+ await guarded[0]("input", agent_ctx=ctx, intent=intent)
81
+ ```
82
+
83
+ ## 📜 Development
84
+
85
+ ```bash
86
+ # Install
87
+ make install
88
+
89
+ # Run Tests
90
+ make test
91
+
92
+ # Run Examples (non-interactive)
93
+ python examples/mcp_minimal/demo.py
94
+ python examples/strands_minimal/demo.py
95
+ ```
96
+
97
+ ## ⚖️ License
98
+ Apache-2.0
@@ -0,0 +1,133 @@
1
+ # tollgate Quickstart Guide 🚀
2
+
3
+ Get started with `tollgate` in minutes. This guide covers the basic setup and integration options for various AI frameworks.
4
+
5
+ ---
6
+
7
+ ## 0. Key Concepts
8
+
9
+ Tollgate requires three pieces of context for every decision:
10
+ - **AgentContext**: Who is asking? (agent_id, version, owner)
11
+ - **Intent**: What is the goal? (action, reason)
12
+ - **Registry**: What does this tool actually do? (defined in `manifest.yaml`)
13
+
14
+ ---
15
+
16
+ ## 1. Installation
17
+
18
+ ```bash
19
+ pip install tollgate
20
+ ```
21
+
22
+ ---
23
+
24
+ ## 2. Shared Setup (Registry & Policy)
25
+
26
+ Every integration requires a **Tool Registry** (to define tool effects) and a **Policy** (to define rules).
27
+
28
+ ### Define `manifest.yaml`
29
+ ```yaml
30
+ version: "1.0.0"
31
+ tools:
32
+ "mcp:file_server.read_file": { effect: "read", resource_type: "file" }
33
+ "strands:get_weather": { effect: "read", resource_type: "weather" }
34
+ "langchain:delete_user": { effect: "delete", resource_type: "user" }
35
+ "openai:process_payment": { effect: "write", resource_type: "payment" }
36
+ ```
37
+
38
+ ### Define `policy.yaml`
39
+ ```yaml
40
+ rules:
41
+ - id: allow_reads
42
+ effect: read
43
+ decision: ALLOW
44
+ - id: ask_deletions
45
+ effect: delete
46
+ decision: ASK
47
+ reason: "Sensitive deletion requires human confirmation."
48
+ ```
49
+
50
+ ---
51
+
52
+ ## 3. Integration Options
53
+
54
+ Choose the integration that fits your agent framework.
55
+
56
+ ### 🔹 Option A: MCP (Model Context Protocol)
57
+ Wrap your MCP client to gate all tool calls automatically.
58
+
59
+ ```python
60
+ from tollgate import ControlTower, ToolRegistry, YamlPolicyEvaluator, CliApprover, JsonlAuditSink
61
+ from tollgate.integrations.mcp import TollgateMCPClient
62
+
63
+ # Initialize Tollgate
64
+ registry = ToolRegistry("manifest.yaml")
65
+ tower = ControlTower(
66
+ policy=YamlPolicyEvaluator("policy.yaml"),
67
+ approver=CliApprover(),
68
+ audit=JsonlAuditSink("audit.jsonl")
69
+ )
70
+
71
+ # Wrap your MCP client
72
+ gated_client = TollgateMCPClient(base_client, server_name="file_server", tower=tower, registry=registry)
73
+
74
+ # Use it like a normal client
75
+ await gated_client.call_tool("read_file", {"path": "data.txt"}, agent_ctx=ctx, intent=intent)
76
+ ```
77
+
78
+ ### 🔹 Option B: Strands Agents
79
+ Guard your Strands tools (functions or objects).
80
+
81
+ ```python
82
+ from tollgate.integrations.strands import guard_tools
83
+
84
+ # Wrap your tools
85
+ guarded_tools = guard_tools([get_weather], tower, registry)
86
+
87
+ # Call the guarded tool
88
+ await guarded_tools[0]("London", agent_ctx=ctx, intent=intent)
89
+ ```
90
+
91
+ ### 🔹 Option C: LangChain
92
+ Use `guard_tools` to wrap LangChain tool objects.
93
+
94
+ ```python
95
+ from tollgate.interceptors.langchain import guard_tools
96
+
97
+ # Wrap LangChain tools
98
+ guarded_lc_tools = guard_tools(my_tools, tower, registry)
99
+
100
+ # Tools now require agent_ctx and intent
101
+ await guarded_lc_tools[0].ainvoke({"input": "query"}, agent_ctx=ctx, intent=intent)
102
+ ```
103
+
104
+ ### 🔹 Option D: OpenAI Tools
105
+ Run OpenAI-formatted tool calls through Tollgate.
106
+
107
+ ```python
108
+ from tollgate.interceptors.openai import OpenAIToolRunner
109
+
110
+ runner = OpenAIToolRunner(tower, registry)
111
+ tool_map = {"process_payment": my_payment_func}
112
+
113
+ # Pass the tool calls list from OpenAI response
114
+ results = await runner.run_async(openai_response.tool_calls, tool_map, agent_ctx=ctx, intent=intent)
115
+ ```
116
+
117
+ ---
118
+
119
+ ## 4. Run the Full Demo
120
+
121
+ Explore the built-in mock tickets demo to see ALLOW, DENY, and ASK scenarios in action.
122
+
123
+ ```bash
124
+ # From the project root
125
+ python examples/mock_tickets/demo.py
126
+ ```
127
+
128
+ ## 🛡️ Safe Defaults
129
+ Remember: Any tool **not** in the registry or any action **not** matched by a policy will be **DENIED** by default in v1.0.0.
130
+
131
+ ---
132
+
133
+ **[📊 See the Before vs. After Integration Comparison](./COMPARISON.md)**