agentlock 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 (54) hide show
  1. agentlock-1.0.0/.github/workflows/ci.yml +92 -0
  2. agentlock-1.0.0/.gitignore +21 -0
  3. agentlock-1.0.0/CHANGELOG.md +29 -0
  4. agentlock-1.0.0/CONTRIBUTING.md +102 -0
  5. agentlock-1.0.0/LICENSE +190 -0
  6. agentlock-1.0.0/NOTICE +14 -0
  7. agentlock-1.0.0/PKG-INFO +349 -0
  8. agentlock-1.0.0/README.md +290 -0
  9. agentlock-1.0.0/SECURITY.md +89 -0
  10. agentlock-1.0.0/agentlock/__init__.py +150 -0
  11. agentlock-1.0.0/agentlock/audit.py +241 -0
  12. agentlock-1.0.0/agentlock/auth_providers/__init__.py +69 -0
  13. agentlock-1.0.0/agentlock/cli.py +308 -0
  14. agentlock-1.0.0/agentlock/decorators.py +182 -0
  15. agentlock-1.0.0/agentlock/exceptions.py +142 -0
  16. agentlock-1.0.0/agentlock/gate.py +481 -0
  17. agentlock-1.0.0/agentlock/integrations/__init__.py +25 -0
  18. agentlock-1.0.0/agentlock/integrations/autogen.py +208 -0
  19. agentlock-1.0.0/agentlock/integrations/crewai.py +228 -0
  20. agentlock-1.0.0/agentlock/integrations/fastapi.py +324 -0
  21. agentlock-1.0.0/agentlock/integrations/flask.py +285 -0
  22. agentlock-1.0.0/agentlock/integrations/langchain.py +326 -0
  23. agentlock-1.0.0/agentlock/integrations/mcp.py +212 -0
  24. agentlock-1.0.0/agentlock/policy.py +196 -0
  25. agentlock-1.0.0/agentlock/py.typed +0 -0
  26. agentlock-1.0.0/agentlock/rate_limit.py +101 -0
  27. agentlock-1.0.0/agentlock/redaction.py +124 -0
  28. agentlock-1.0.0/agentlock/schema.py +173 -0
  29. agentlock-1.0.0/agentlock/session.py +130 -0
  30. agentlock-1.0.0/agentlock/token.py +172 -0
  31. agentlock-1.0.0/agentlock/types.py +148 -0
  32. agentlock-1.0.0/docs/integrations.md +155 -0
  33. agentlock-1.0.0/docs/quickstart.md +120 -0
  34. agentlock-1.0.0/docs/specification.md +136 -0
  35. agentlock-1.0.0/examples/data_redaction.py +127 -0
  36. agentlock-1.0.0/examples/decorator_example.py +128 -0
  37. agentlock-1.0.0/examples/fastapi_app.py +208 -0
  38. agentlock-1.0.0/examples/multi_role.py +142 -0
  39. agentlock-1.0.0/examples/quickstart.py +141 -0
  40. agentlock-1.0.0/examples/rate_limiting.py +99 -0
  41. agentlock-1.0.0/pyproject.toml +115 -0
  42. agentlock-1.0.0/schema/agentlock-v1.0.json +334 -0
  43. agentlock-1.0.0/tests/__init__.py +0 -0
  44. agentlock-1.0.0/tests/conftest.py +109 -0
  45. agentlock-1.0.0/tests/test_audit.py +275 -0
  46. agentlock-1.0.0/tests/test_cli.py +224 -0
  47. agentlock-1.0.0/tests/test_decorators.py +135 -0
  48. agentlock-1.0.0/tests/test_gate.py +349 -0
  49. agentlock-1.0.0/tests/test_policy.py +361 -0
  50. agentlock-1.0.0/tests/test_rate_limit.py +131 -0
  51. agentlock-1.0.0/tests/test_redaction.py +130 -0
  52. agentlock-1.0.0/tests/test_schema.py +310 -0
  53. agentlock-1.0.0/tests/test_session.py +168 -0
  54. agentlock-1.0.0/tests/test_token.py +202 -0
@@ -0,0 +1,92 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ pip install -e ".[dev]"
31
+
32
+ - name: Lint with ruff
33
+ run: ruff check agentlock/ tests/
34
+
35
+ - name: Type check with mypy
36
+ run: mypy agentlock/ --ignore-missing-imports
37
+ continue-on-error: true
38
+
39
+ - name: Run tests
40
+ run: pytest --cov=agentlock --cov-report=xml -v
41
+
42
+ - name: Upload coverage
43
+ if: matrix.python-version == '3.12'
44
+ uses: codecov/codecov-action@v4
45
+ with:
46
+ file: coverage.xml
47
+ continue-on-error: true
48
+
49
+ build:
50
+ runs-on: ubuntu-latest
51
+ needs: test
52
+ steps:
53
+ - uses: actions/checkout@v4
54
+
55
+ - name: Set up Python
56
+ uses: actions/setup-python@v5
57
+ with:
58
+ python-version: "3.12"
59
+
60
+ - name: Install build tools
61
+ run: pip install build
62
+
63
+ - name: Build package
64
+ run: python -m build
65
+
66
+ - name: Check package
67
+ run: |
68
+ pip install twine
69
+ twine check dist/*
70
+
71
+ publish:
72
+ runs-on: ubuntu-latest
73
+ needs: build
74
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
75
+ permissions:
76
+ id-token: write
77
+ steps:
78
+ - uses: actions/checkout@v4
79
+
80
+ - name: Set up Python
81
+ uses: actions/setup-python@v5
82
+ with:
83
+ python-version: "3.12"
84
+
85
+ - name: Install build tools
86
+ run: pip install build
87
+
88
+ - name: Build package
89
+ run: python -m build
90
+
91
+ - name: Publish to PyPI
92
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,21 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+ .eggs/
9
+ .mypy_cache/
10
+ .pytest_cache/
11
+ .ruff_cache/
12
+ .coverage
13
+ htmlcov/
14
+ *.so
15
+ .env
16
+ .venv/
17
+ venv/
18
+ env/
19
+ *.log
20
+ .DS_Store
21
+ Thumbs.db
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to AgentLock will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-03-18
9
+
10
+ ### Added
11
+
12
+ - Core AgentLock permissions schema (v1.0)
13
+ - `AuthorizationGate` — central enforcement point with deny-by-default semantics
14
+ - `AgentLockPermissions` — Pydantic model for the `agentlock` permissions block
15
+ - `@agentlock` decorator for one-line tool protection
16
+ - Single-use, time-limited, operation-bound execution tokens
17
+ - Session management with expiry and scope tracking
18
+ - Sliding-window per-user, per-tool rate limiting
19
+ - Automatic data redaction engine with built-in PII patterns
20
+ - Policy evaluation engine with 7-step authorization checks
21
+ - Pluggable audit logging with file and in-memory backends
22
+ - CLI tool: `agentlock validate`, `agentlock schema`, `agentlock init`, `agentlock inspect`, `agentlock audit`
23
+ - Framework integrations: LangChain, CrewAI, AutoGen, MCP, FastAPI, Flask
24
+ - JSON Schema for tool definition validation
25
+ - Comprehensive test suite
26
+ - Working examples for all major use cases
27
+ - Full documentation
28
+ - GitHub Actions CI/CD pipeline
29
+ - Apache 2.0 license
@@ -0,0 +1,102 @@
1
+ # Contributing to AgentLock
2
+
3
+ Thank you for your interest in contributing to AgentLock. This project aims to establish an open standard for authorization in AI agent systems.
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ git clone https://github.com/webpro255/agentlock.git
9
+ cd agentlock
10
+ pip install -e ".[dev]"
11
+ pytest
12
+ ```
13
+
14
+ ## Development Workflow
15
+
16
+ 1. **Fork** the repository
17
+ 2. **Create a branch** from `main`: `git checkout -b my-feature`
18
+ 3. **Make your changes** with tests
19
+ 4. **Run the checks:**
20
+ ```bash
21
+ pytest -v # Tests pass
22
+ ruff check agentlock/ tests/ # Zero lint errors
23
+ mypy agentlock/ --ignore-missing-imports # Zero type errors
24
+ ```
25
+ 5. **Commit** with a clear message
26
+ 6. **Open a Pull Request** against `main`
27
+
28
+ ## Code Standards
29
+
30
+ - **Python 3.10+** — all code must support Python 3.10 and above
31
+ - **Type hints everywhere** — all function signatures must be annotated
32
+ - **`from __future__ import annotations`** — required in every module
33
+ - **Google-style docstrings** — for all public classes and functions
34
+ - **Pydantic v2** — for schema models
35
+ - **No unnecessary dependencies** — core library depends only on `pydantic`
36
+
37
+ ## Testing
38
+
39
+ - All new features must include tests
40
+ - All bug fixes must include a regression test
41
+ - Tests go in `tests/` following the existing pattern
42
+ - Use `pytest` fixtures from `tests/conftest.py`
43
+ - Prefer monkeypatching `time.time()` over `time.sleep()` for expiry tests
44
+
45
+ ```bash
46
+ # Run all tests
47
+ pytest -v
48
+
49
+ # Run with coverage
50
+ pytest --cov=agentlock --cov-report=term-missing
51
+
52
+ # Run a specific test file
53
+ pytest tests/test_gate.py -v
54
+ ```
55
+
56
+ ## What to Contribute
57
+
58
+ ### High Priority
59
+
60
+ - **Real-world integration testing** — test with actual LangChain, CrewAI, AutoGen deployments
61
+ - **Additional audit backends** — Redis, PostgreSQL, CloudWatch, Datadog
62
+ - **Additional auth providers** — OAuth2 providers, SAML, OIDC
63
+ - **Performance benchmarks** — measure gate overhead at scale
64
+ - **Documentation improvements** — tutorials, guides, API reference
65
+
66
+ ### Schema Extensions (v1.1+)
67
+
68
+ - Memory and context permissions
69
+ - Conditional permissions (time, location, context)
70
+ - Tool chain permissions for multi-step workflows
71
+ - Multi-agent identity delegation
72
+
73
+ ### Reporting Issues
74
+
75
+ - Use [GitHub Issues](https://github.com/webpro255/agentlock/issues)
76
+ - Include Python version, OS, and agentlock version
77
+ - Include a minimal reproducible example
78
+ - For security vulnerabilities, see [SECURITY.md](SECURITY.md)
79
+
80
+ ## Pull Request Guidelines
81
+
82
+ - **One feature per PR** — keep changes focused
83
+ - **Update tests** — new code needs tests
84
+ - **Update docs** — if you change the API, update the docs
85
+ - **No breaking changes without discussion** — open an issue first
86
+ - **Keep commits clean** — squash fixup commits before merge
87
+
88
+ ## Architecture Notes
89
+
90
+ - `agentlock/gate.py` — Central enforcement point. Changes here affect everything.
91
+ - `agentlock/schema.py` — Pydantic models for the spec. Changes here affect the standard.
92
+ - `agentlock/policy.py` — Policy evaluation. Check order matters.
93
+ - `agentlock/integrations/` — Framework wrappers. Must lazy-import framework dependencies.
94
+ - `schema/agentlock-v1.0.json` — Hand-written JSON schema. Must stay in sync with Pydantic models.
95
+
96
+ ## License
97
+
98
+ By contributing, you agree that your contributions will be licensed under the Apache License 2.0.
99
+
100
+ ## Code of Conduct
101
+
102
+ Be respectful, constructive, and professional. We're building infrastructure that protects people. Act accordingly.
@@ -0,0 +1,190 @@
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 the 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 the 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 any 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
177
+
178
+ Copyright 2026 David Grice (AgentShield — agent-shield.com)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
agentlock-1.0.0/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ AgentLock
2
+ Copyright 2026 David Grice (AgentShield — agent-shield.com)
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.