aegislib 0.1.1__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.
- aegislib-0.1.1/CHANGELOG.md +32 -0
- aegislib-0.1.1/CONTRIBUTING.md +241 -0
- aegislib-0.1.1/LICENSE +21 -0
- aegislib-0.1.1/MANIFEST.in +14 -0
- aegislib-0.1.1/PKG-INFO +369 -0
- aegislib-0.1.1/README.md +321 -0
- aegislib-0.1.1/aegis/__init__.py +33 -0
- aegislib-0.1.1/aegis/_version.py +3 -0
- aegislib-0.1.1/aegis/config.py +106 -0
- aegislib-0.1.1/aegis/decision.py +57 -0
- aegislib-0.1.1/aegis/errors.py +89 -0
- aegislib-0.1.1/aegis/guard.py +181 -0
- aegislib-0.1.1/aegis/http.py +110 -0
- aegislib-0.1.1/aegis/logging.py +101 -0
- aegislib-0.1.1/aegis/py.typed +1 -0
- aegislib-0.1.1/aegis/types.py +115 -0
- aegislib-0.1.1/aegis/util.py +57 -0
- aegislib-0.1.1/aegislib.egg-info/PKG-INFO +369 -0
- aegislib-0.1.1/aegislib.egg-info/SOURCES.txt +24 -0
- aegislib-0.1.1/aegislib.egg-info/dependency_links.txt +1 -0
- aegislib-0.1.1/aegislib.egg-info/not-zip-safe +1 -0
- aegislib-0.1.1/aegislib.egg-info/requires.txt +21 -0
- aegislib-0.1.1/aegislib.egg-info/top_level.txt +1 -0
- aegislib-0.1.1/pyproject.toml +184 -0
- aegislib-0.1.1/setup.cfg +40 -0
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.1] - 2025-11-06
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Initial release of Aegis Python SDK
|
|
14
|
+
- Core `@aegis_guard` decorator for tool protection
|
|
15
|
+
- `AegisConfig` for SDK configuration with environment variable support
|
|
16
|
+
- `DecisionClient` for interacting with Aegis Data Plane
|
|
17
|
+
- Full support for allow/deny/sanitize/approval_needed decisions
|
|
18
|
+
- Async/await compatibility for async functions
|
|
19
|
+
- Built-in retry logic and resilience features
|
|
20
|
+
- Type hints and py.typed marker for type checking
|
|
21
|
+
- Comprehensive error handling with custom exception hierarchy
|
|
22
|
+
- Debug logging and console output utilities
|
|
23
|
+
- Complete unit test suite with 100% code coverage
|
|
24
|
+
- CI/CD workflows for automated testing and publishing
|
|
25
|
+
- Production-ready packaging for PyPI distribution
|
|
26
|
+
|
|
27
|
+
### Security
|
|
28
|
+
- Secure API key handling with Pydantic SecretStr
|
|
29
|
+
- Safe model dumping with masked sensitive fields
|
|
30
|
+
|
|
31
|
+
[Unreleased]: https://github.com/mrsidrdx/aegis-python-sdk/compare/v0.1.1...HEAD
|
|
32
|
+
[0.1.1]: https://github.com/mrsidrdx/aegis-python-sdk/releases/tag/v0.1.1
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Contributing to Aegis Python SDK
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to Aegis! This document provides guidelines and instructions for contributing.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Code of Conduct](#code-of-conduct)
|
|
8
|
+
- [Getting Started](#getting-started)
|
|
9
|
+
- [Development Setup](#development-setup)
|
|
10
|
+
- [Running Tests](#running-tests)
|
|
11
|
+
- [Code Style](#code-style)
|
|
12
|
+
- [Making Changes](#making-changes)
|
|
13
|
+
- [Submitting Changes](#submitting-changes)
|
|
14
|
+
|
|
15
|
+
## Code of Conduct
|
|
16
|
+
|
|
17
|
+
We expect all contributors to be respectful and professional. Please be kind and courteous in all interactions.
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
1. Fork the repository on GitHub
|
|
22
|
+
2. Clone your fork locally
|
|
23
|
+
3. Create a new branch for your changes
|
|
24
|
+
4. Make your changes
|
|
25
|
+
5. Submit a pull request
|
|
26
|
+
|
|
27
|
+
## Development Setup
|
|
28
|
+
|
|
29
|
+
### Prerequisites
|
|
30
|
+
|
|
31
|
+
- Python 3.11 or higher
|
|
32
|
+
- pip or another package manager
|
|
33
|
+
|
|
34
|
+
### Installation
|
|
35
|
+
|
|
36
|
+
1. Clone the repository:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/mrsidrdx/aegis-python-sdk.git
|
|
40
|
+
cd aegis-python-sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
2. Create a virtual environment:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python -m venv venv
|
|
47
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3. Install development dependencies:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install -e ".[dev]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Running Tests
|
|
57
|
+
|
|
58
|
+
### Run all tests
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Run tests with coverage
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pytest --cov=aegis --cov-report=html --cov-report=term
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Run specific test file
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pytest tests/test_config.py
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Run with verbose output
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pytest -v
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### View coverage report
|
|
83
|
+
|
|
84
|
+
After running tests with coverage, open `htmlcov/index.html` in your browser.
|
|
85
|
+
|
|
86
|
+
## Code Style
|
|
87
|
+
|
|
88
|
+
We use the following tools to maintain code quality:
|
|
89
|
+
|
|
90
|
+
- **Black**: Code formatting
|
|
91
|
+
- **Ruff**: Linting and import sorting
|
|
92
|
+
- **MyPy**: Type checking
|
|
93
|
+
|
|
94
|
+
### Format code
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
black aegis/ tests/
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Run linter
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
ruff check aegis/ tests/
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Run type checker
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
mypy aegis/
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Run all checks
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
make lint
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Making Changes
|
|
119
|
+
|
|
120
|
+
### Adding New Features
|
|
121
|
+
|
|
122
|
+
1. Create a new branch from `main`:
|
|
123
|
+
```bash
|
|
124
|
+
git checkout -b feature/your-feature-name
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
2. Write tests for your feature first (TDD approach)
|
|
128
|
+
3. Implement your feature
|
|
129
|
+
4. Ensure all tests pass
|
|
130
|
+
5. Update documentation if necessary
|
|
131
|
+
|
|
132
|
+
### Fixing Bugs
|
|
133
|
+
|
|
134
|
+
1. Create a new branch from `main`:
|
|
135
|
+
```bash
|
|
136
|
+
git checkout -b fix/bug-description
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
2. Write a test that reproduces the bug
|
|
140
|
+
3. Fix the bug
|
|
141
|
+
4. Ensure all tests pass
|
|
142
|
+
|
|
143
|
+
### Code Coverage
|
|
144
|
+
|
|
145
|
+
We maintain 100% test coverage. All new code must include tests.
|
|
146
|
+
|
|
147
|
+
To check coverage:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
pytest --cov=aegis --cov-report=term-missing
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Submitting Changes
|
|
154
|
+
|
|
155
|
+
### Before Submitting
|
|
156
|
+
|
|
157
|
+
1. Ensure all tests pass:
|
|
158
|
+
```bash
|
|
159
|
+
pytest
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
2. Ensure code is formatted:
|
|
163
|
+
```bash
|
|
164
|
+
black aegis/ tests/
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
3. Ensure linting passes:
|
|
168
|
+
```bash
|
|
169
|
+
ruff check aegis/ tests/
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
4. Ensure type checking passes:
|
|
173
|
+
```bash
|
|
174
|
+
mypy aegis/
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
5. Update CHANGELOG.md with your changes
|
|
178
|
+
|
|
179
|
+
### Pull Request Process
|
|
180
|
+
|
|
181
|
+
1. Push your changes to your fork
|
|
182
|
+
2. Create a pull request against the `main` branch
|
|
183
|
+
3. Provide a clear description of the changes
|
|
184
|
+
4. Link any related issues
|
|
185
|
+
5. Wait for review and address feedback
|
|
186
|
+
|
|
187
|
+
### Pull Request Guidelines
|
|
188
|
+
|
|
189
|
+
- Keep PRs focused and small
|
|
190
|
+
- Include tests for all changes
|
|
191
|
+
- Update documentation as needed
|
|
192
|
+
- Follow existing code style
|
|
193
|
+
- Write clear commit messages
|
|
194
|
+
|
|
195
|
+
## Commit Message Format
|
|
196
|
+
|
|
197
|
+
We follow conventional commit format:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
type(scope): subject
|
|
201
|
+
|
|
202
|
+
body
|
|
203
|
+
|
|
204
|
+
footer
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Types:
|
|
208
|
+
- `feat`: New feature
|
|
209
|
+
- `fix`: Bug fix
|
|
210
|
+
- `docs`: Documentation changes
|
|
211
|
+
- `style`: Code style changes (formatting, etc.)
|
|
212
|
+
- `refactor`: Code refactoring
|
|
213
|
+
- `test`: Test changes
|
|
214
|
+
- `chore`: Build process or auxiliary tool changes
|
|
215
|
+
|
|
216
|
+
Example:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
feat(guard): add support for custom decision handlers
|
|
220
|
+
|
|
221
|
+
Added ability to provide custom handlers for each decision effect type,
|
|
222
|
+
allowing users to customize behavior beyond the default implementation.
|
|
223
|
+
|
|
224
|
+
Closes #123
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Questions?
|
|
228
|
+
|
|
229
|
+
If you have questions, please:
|
|
230
|
+
|
|
231
|
+
1. Check existing issues and discussions
|
|
232
|
+
2. Open a new issue with your question
|
|
233
|
+
3. Be clear and provide context
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
|
238
|
+
|
|
239
|
+
## Thank You!
|
|
240
|
+
|
|
241
|
+
Your contributions make Aegis better for everyone. Thank you for taking the time to contribute!
|
aegislib-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aegis Security
|
|
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,14 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
include CONTRIBUTING.md
|
|
5
|
+
include pyproject.toml
|
|
6
|
+
include setup.cfg
|
|
7
|
+
recursive-include aegis *.py
|
|
8
|
+
recursive-include aegis py.typed
|
|
9
|
+
recursive-exclude tests *
|
|
10
|
+
recursive-exclude examples *
|
|
11
|
+
recursive-exclude .github *
|
|
12
|
+
recursive-exclude * __pycache__
|
|
13
|
+
recursive-exclude * *.py[co]
|
|
14
|
+
recursive-exclude * .DS_Store
|
aegislib-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aegislib
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Aegis Python SDK - Secure AI agents tool guard integration
|
|
5
|
+
Home-page: https://github.com/mrsidrdx/aegis-python-sdk
|
|
6
|
+
Author: Siddhartha Satyakama
|
|
7
|
+
Author-email: Aegis Team <bithal06@gmail.com>
|
|
8
|
+
Maintainer-email: mrsidrdx <bithal06@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://github.com/mrsidrdx/aegis-python-sdk
|
|
11
|
+
Project-URL: Documentation, https://github.com/mrsidrdx/aegis-python-sdk
|
|
12
|
+
Project-URL: Repository, https://github.com/mrsidrdx/aegis-python-sdk
|
|
13
|
+
Project-URL: Issues, https://github.com/mrsidrdx/aegis-python-sdk/issues
|
|
14
|
+
Keywords: ai,security,policy,agent,tool,guard
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: httpx>=0.25.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Requires-Dist: backoff>=2.2.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: ruff>=0.1.1; extra == "dev"
|
|
38
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.7.0; extra == "dev"
|
|
40
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pytest>=7.4.0; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
46
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "test"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# Aegis Python SDK
|
|
50
|
+
|
|
51
|
+
[](https://github.com/mrsidrdx/aegis-python-sdk/actions)
|
|
52
|
+
[](https://pypi.org/project/aegis/)
|
|
53
|
+
[](https://pypi.org/project/aegis/)
|
|
54
|
+
[](https://codecov.io/gh/aegis/aegis-python-sdk)
|
|
55
|
+
[](https://opensource.org/licenses/MIT)
|
|
56
|
+
[](https://github.com/psf/black)
|
|
57
|
+
|
|
58
|
+
Secure AI tool guard integration for multi-agent frameworks.
|
|
59
|
+
|
|
60
|
+
Aegis enables developers to integrate policy-based AI tool security directly into their agent workflows with minimal effort. It provides a simple `@aegis_guard` decorator or wrapper to protect any tool call, with automatic decision requests to the Aegis Data Plane and enforcement of allow/deny/sanitize policies in real time.
|
|
61
|
+
|
|
62
|
+
## Features
|
|
63
|
+
|
|
64
|
+
- **Simple Decorator**: One-line `@aegis_guard` decorator for any Python function
|
|
65
|
+
- **Framework Agnostic**: Core SDK works with any Python code
|
|
66
|
+
- **Real-time Policy Enforcement**: Automatic allow/deny/sanitize decisions
|
|
67
|
+
- **Async Support**: Full async/await compatibility
|
|
68
|
+
- **Resilient**: Built-in retries, timeouts, and error handling
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install aegislib
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from aegis import AegisConfig, DecisionClient, aegis_guard
|
|
80
|
+
|
|
81
|
+
# Configure the SDK
|
|
82
|
+
cfg = AegisConfig(api_key="your-api-key")
|
|
83
|
+
client = DecisionClient(cfg)
|
|
84
|
+
|
|
85
|
+
# Guard any tool function
|
|
86
|
+
@aegis_guard(client, agent_id="ops-agent", tool_name="slack.post_message")
|
|
87
|
+
def post_to_slack(channel: str, text: str):
|
|
88
|
+
print(f"Sending message: {text} to {channel}")
|
|
89
|
+
|
|
90
|
+
# Use normally - Aegis will decide allow/deny/sanitize automatically
|
|
91
|
+
post_to_slack("#support", "Hello!")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
Configure via environment variables:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
export AEGIS_API_KEY="your-api-key"
|
|
100
|
+
export AEGIS_TIMEOUT_S="1.0"
|
|
101
|
+
export AEGIS_RETRIES="2"
|
|
102
|
+
export AEGIS_LOG_LEVEL="info"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or programmatically:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
cfg = AegisConfig(
|
|
109
|
+
api_key="your-api-key",
|
|
110
|
+
timeout_s=1.0,
|
|
111
|
+
retries=2,
|
|
112
|
+
log_level="info"
|
|
113
|
+
)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Advanced Usage
|
|
117
|
+
|
|
118
|
+
### Async Support
|
|
119
|
+
|
|
120
|
+
Aegis fully supports async functions:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
@aegis_guard(client, agent_id="async-agent", tool_name="async_tool")
|
|
124
|
+
async def fetch_data(url: str) -> dict:
|
|
125
|
+
async with httpx.AsyncClient() as http:
|
|
126
|
+
response = await http.get(url)
|
|
127
|
+
return response.json()
|
|
128
|
+
|
|
129
|
+
# Use with await
|
|
130
|
+
data = await fetch_data("https://api.example.com/data")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Custom Configuration
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from aegis import AegisConfig, DecisionClient
|
|
137
|
+
|
|
138
|
+
# Detailed configuration
|
|
139
|
+
config = AegisConfig(
|
|
140
|
+
base_url="https://api.aegis.cloudmatos.ai",
|
|
141
|
+
api_key="your-api-key",
|
|
142
|
+
timeout_s=5.0, # Request timeout
|
|
143
|
+
retries=3, # Number of retries
|
|
144
|
+
log_level="debug", # Logging level
|
|
145
|
+
debug=True, # Enable debug output
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
client = DecisionClient(config)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Decision Effects
|
|
152
|
+
|
|
153
|
+
Aegis supports four decision effects:
|
|
154
|
+
|
|
155
|
+
1. **Allow**: Tool execution proceeds normally
|
|
156
|
+
2. **Deny**: Tool execution is blocked with `ForbiddenError`
|
|
157
|
+
3. **Sanitize**: Parameters are modified before execution
|
|
158
|
+
4. **Approval Needed**: Requires manual approval
|
|
159
|
+
|
|
160
|
+
### Error Handling
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from aegis import ForbiddenError, AuthError, TransportError
|
|
164
|
+
|
|
165
|
+
@aegis_guard(client, agent_id="agent", tool_name="risky_tool")
|
|
166
|
+
def risky_operation(data: str) -> str:
|
|
167
|
+
return f"Processing: {data}"
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
result = risky_operation("sensitive data")
|
|
171
|
+
except ForbiddenError as e:
|
|
172
|
+
print(f"Operation blocked: {e}")
|
|
173
|
+
except AuthError as e:
|
|
174
|
+
print(f"Authentication failed: {e}")
|
|
175
|
+
except TransportError as e:
|
|
176
|
+
print(f"Network error: {e}")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Session Context
|
|
180
|
+
|
|
181
|
+
Pass additional context with your requests:
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
session_data = {
|
|
185
|
+
"user_id": "user-123",
|
|
186
|
+
"session_id": "sess-456",
|
|
187
|
+
"context": "production"
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
# Manually call decide with session
|
|
191
|
+
response = client.decide(
|
|
192
|
+
agent_id="agent",
|
|
193
|
+
tool_name="tool",
|
|
194
|
+
params={"key": "value"},
|
|
195
|
+
session=session_data
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## API Reference
|
|
200
|
+
|
|
201
|
+
### AegisConfig
|
|
202
|
+
|
|
203
|
+
Configuration class for the SDK.
|
|
204
|
+
|
|
205
|
+
**Parameters:**
|
|
206
|
+
- `base_url` (str): Aegis Data Plane endpoint URL
|
|
207
|
+
- `api_key` (str): Tenant API key for authentication
|
|
208
|
+
- `timeout_s` (float): HTTP request timeout in seconds (default: 10.0)
|
|
209
|
+
- `retries` (int): Number of retry attempts (default: 2)
|
|
210
|
+
- `user_agent` (str): User agent string (default: "aegis-python-sdk/0.1.1")
|
|
211
|
+
- `log_level` (str): Logging level (default: "info")
|
|
212
|
+
- `debug` (bool): Enable debug mode (default: False)
|
|
213
|
+
|
|
214
|
+
**Environment Variables:**
|
|
215
|
+
- `AEGIS_BASE_URL`: Override base URL
|
|
216
|
+
- `AEGIS_API_KEY`: Override API key
|
|
217
|
+
- `AEGIS_TIMEOUT_S`: Override timeout
|
|
218
|
+
- `AEGIS_RETRIES`: Override retries
|
|
219
|
+
- `AEGIS_LOG_LEVEL`: Override log level
|
|
220
|
+
- `AEGIS_DEBUG`: Override debug mode
|
|
221
|
+
|
|
222
|
+
### DecisionClient
|
|
223
|
+
|
|
224
|
+
Client for interacting with Aegis Decision API.
|
|
225
|
+
|
|
226
|
+
**Methods:**
|
|
227
|
+
- `decide(agent_id, tool_name, params, session=None)`: Request a decision
|
|
228
|
+
- `close()`: Close the HTTP client
|
|
229
|
+
|
|
230
|
+
### aegis_guard
|
|
231
|
+
|
|
232
|
+
Decorator for guarding tool functions.
|
|
233
|
+
|
|
234
|
+
**Parameters:**
|
|
235
|
+
- `client` (DecisionClient): Configured client instance
|
|
236
|
+
- `agent_id` (str): Agent identifier
|
|
237
|
+
- `tool_name` (str, optional): Tool name (defaults to function name)
|
|
238
|
+
|
|
239
|
+
**Returns:** Decorated function
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
### Setup
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Clone the repository
|
|
247
|
+
git clone https://github.com/mrsidrdx/aegis-python-sdk.git
|
|
248
|
+
cd aegis-python-sdk
|
|
249
|
+
|
|
250
|
+
# Create virtual environment
|
|
251
|
+
python -m venv venv
|
|
252
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
253
|
+
|
|
254
|
+
# Install development dependencies
|
|
255
|
+
make install-dev
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Running Tests
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Run all tests with coverage
|
|
262
|
+
make test-cov
|
|
263
|
+
|
|
264
|
+
# Run tests without coverage
|
|
265
|
+
make test-fast
|
|
266
|
+
|
|
267
|
+
# Run specific test file
|
|
268
|
+
pytest tests/test_config.py
|
|
269
|
+
|
|
270
|
+
# Run with verbose output
|
|
271
|
+
pytest -v
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Code Quality
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Run all linting checks
|
|
278
|
+
make lint
|
|
279
|
+
|
|
280
|
+
# Format code
|
|
281
|
+
make format
|
|
282
|
+
|
|
283
|
+
# Type checking
|
|
284
|
+
make type-check
|
|
285
|
+
|
|
286
|
+
# Security checks
|
|
287
|
+
make security
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Building
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Build distribution packages
|
|
294
|
+
make build
|
|
295
|
+
|
|
296
|
+
# Check packages
|
|
297
|
+
make check-dist
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Publishing
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Publish to Test PyPI
|
|
304
|
+
make publish-test
|
|
305
|
+
|
|
306
|
+
# Publish to PyPI (requires confirmation)
|
|
307
|
+
make publish
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Testing
|
|
311
|
+
|
|
312
|
+
The SDK includes comprehensive unit tests with 100% code coverage:
|
|
313
|
+
|
|
314
|
+
- Configuration management (`test_config.py`)
|
|
315
|
+
- Error handling (`test_errors.py`)
|
|
316
|
+
- Type definitions (`test_types.py`)
|
|
317
|
+
- Utility functions (`test_util.py`)
|
|
318
|
+
- Logging (`test_logging.py`)
|
|
319
|
+
- HTTP client (`test_http.py`)
|
|
320
|
+
- Decision client (`test_decision.py`)
|
|
321
|
+
- Guard decorator (`test_guard.py`)
|
|
322
|
+
|
|
323
|
+
Run tests with:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
pytest --cov=aegis --cov-report=html
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
View coverage report at `htmlcov/index.html`.
|
|
330
|
+
|
|
331
|
+
## CI/CD
|
|
332
|
+
|
|
333
|
+
The project uses GitHub Actions for continuous integration and deployment:
|
|
334
|
+
|
|
335
|
+
- **CI Workflow**: Runs tests on multiple Python versions (3.11, 3.12, 3.13) and platforms (Linux, macOS, Windows)
|
|
336
|
+
- **Publish Workflow**: Automatically publishes to PyPI on release
|
|
337
|
+
- **Release Workflow**: Creates GitHub releases with changelog
|
|
338
|
+
|
|
339
|
+
## Versioning
|
|
340
|
+
|
|
341
|
+
This project follows [Semantic Versioning](https://semver.org/):
|
|
342
|
+
|
|
343
|
+
- **MAJOR**: Incompatible API changes
|
|
344
|
+
- **MINOR**: New functionality (backward compatible)
|
|
345
|
+
- **PATCH**: Bug fixes (backward compatible)
|
|
346
|
+
|
|
347
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
348
|
+
|
|
349
|
+
## License
|
|
350
|
+
|
|
351
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
352
|
+
|
|
353
|
+
## Contributing
|
|
354
|
+
|
|
355
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for:
|
|
356
|
+
|
|
357
|
+
- Development setup
|
|
358
|
+
- Code style guidelines
|
|
359
|
+
- Testing requirements
|
|
360
|
+
- Pull request process
|
|
361
|
+
|
|
362
|
+
## Support
|
|
363
|
+
|
|
364
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/mrsidrdx/aegis-python-sdk/issues)
|
|
365
|
+
- **Email**: bithal06@gmail.com
|
|
366
|
+
|
|
367
|
+
## Acknowledgments
|
|
368
|
+
|
|
369
|
+
Built with ❤️ by the Aegis team and contributors.
|