agentguard-eu 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.
- agentguard_eu-0.1.0/.gitignore +52 -0
- agentguard_eu-0.1.0/CHANGELOG.md +28 -0
- agentguard_eu-0.1.0/LICENSE +15 -0
- agentguard_eu-0.1.0/PKG-INFO +459 -0
- agentguard_eu-0.1.0/README.md +407 -0
- agentguard_eu-0.1.0/agentguard/__init__.py +50 -0
- agentguard_eu-0.1.0/agentguard/audit.py +229 -0
- agentguard_eu-0.1.0/agentguard/config.py +151 -0
- agentguard_eu-0.1.0/agentguard/core.py +462 -0
- agentguard_eu-0.1.0/agentguard/dashboard.py +404 -0
- agentguard_eu-0.1.0/agentguard/disclosure.py +150 -0
- agentguard_eu-0.1.0/agentguard/human_loop.py +178 -0
- agentguard_eu-0.1.0/agentguard/py.typed +0 -0
- agentguard_eu-0.1.0/agentguard/report.py +187 -0
- agentguard_eu-0.1.0/agentguard/wrappers/__init__.py +1 -0
- agentguard_eu-0.1.0/agentguard/wrappers/anthropic.py +198 -0
- agentguard_eu-0.1.0/agentguard/wrappers/azure_openai.py +62 -0
- agentguard_eu-0.1.0/agentguard/wrappers/langchain.py +231 -0
- agentguard_eu-0.1.0/agentguard/wrappers/openai.py +183 -0
- agentguard_eu-0.1.0/examples/anthropic_example.py +95 -0
- agentguard_eu-0.1.0/examples/azure_openai_example.py +97 -0
- agentguard_eu-0.1.0/examples/basic_usage.py +132 -0
- agentguard_eu-0.1.0/examples/fastapi_example.py +154 -0
- agentguard_eu-0.1.0/examples/langchain_azure_example.py +95 -0
- agentguard_eu-0.1.0/examples/openai_example.py +91 -0
- agentguard_eu-0.1.0/pyproject.toml +69 -0
- agentguard_eu-0.1.0/tests/test_anthropic_wrapper.py +414 -0
- agentguard_eu-0.1.0/tests/test_azure_openai_wrapper.py +298 -0
- agentguard_eu-0.1.0/tests/test_core.py +209 -0
- agentguard_eu-0.1.0/tests/test_langchain_wrapper.py +445 -0
- agentguard_eu-0.1.0/tests/test_openai_wrapper.py +361 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# Testing
|
|
18
|
+
.pytest_cache/
|
|
19
|
+
.coverage
|
|
20
|
+
htmlcov/
|
|
21
|
+
.tox/
|
|
22
|
+
.nox/
|
|
23
|
+
examples/generate_sample_data.py
|
|
24
|
+
|
|
25
|
+
# Type checking
|
|
26
|
+
.mypy_cache/
|
|
27
|
+
|
|
28
|
+
# Linting
|
|
29
|
+
.ruff_cache/
|
|
30
|
+
|
|
31
|
+
# IDEs
|
|
32
|
+
.vscode/
|
|
33
|
+
.idea/
|
|
34
|
+
*.swp
|
|
35
|
+
*.swo
|
|
36
|
+
*~
|
|
37
|
+
|
|
38
|
+
# Environment variables
|
|
39
|
+
.env
|
|
40
|
+
.env.local
|
|
41
|
+
|
|
42
|
+
# OS files
|
|
43
|
+
.DS_Store
|
|
44
|
+
Thumbs.db
|
|
45
|
+
|
|
46
|
+
# AgentGuard runtime artifacts
|
|
47
|
+
agentguard_audit/
|
|
48
|
+
*.db
|
|
49
|
+
|
|
50
|
+
# Claude Code / Playbook
|
|
51
|
+
CLAUDE.md
|
|
52
|
+
CLAUDE_CODE_PLAYBOOK.md
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to AgentGuard 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
|
+
## [0.1.0] - 2026-02-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Core `AgentGuard` class with three usage patterns: `invoke()`, `@compliant` decorator, `interaction()` context manager
|
|
13
|
+
- EU AI Act compliance pipeline: escalation check, disclosure injection, content labeling, audit logging
|
|
14
|
+
- `AuditLogger` with FILE (JSONL), SQLITE, and CUSTOM backends
|
|
15
|
+
- `DisclosureManager` for Article 50 transparency (prepend, metadata, HTTP headers, C2PA assertions)
|
|
16
|
+
- `HumanOversight` with confidence-based and keyword-based escalation, in-memory review queue
|
|
17
|
+
- `ComplianceReporter` generating JSON and Markdown compliance reports
|
|
18
|
+
- Provider wrappers:
|
|
19
|
+
- `wrap_openai()` — OpenAI client monkey-patch (streaming + non-streaming)
|
|
20
|
+
- `wrap_azure_openai()` — Azure OpenAI client wrapper
|
|
21
|
+
- `wrap_anthropic()` — Anthropic client monkey-patch (streaming + non-streaming)
|
|
22
|
+
- `AgentGuardCallback` — LangChain `BaseCallbackHandler` for any LangChain LLM
|
|
23
|
+
- Streamlit human review dashboard (`agentguard-dashboard` CLI)
|
|
24
|
+
- 90 tests covering core, all wrappers, escalation, audit, and error handling
|
|
25
|
+
- FastAPI integration example
|
|
26
|
+
- Example scripts for OpenAI, Azure OpenAI, Anthropic, and LangChain
|
|
27
|
+
|
|
28
|
+
[0.1.0]: https://github.com/Sagar-Gogineni/agentguard/releases/tag/v0.1.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentguard-eu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: EU AI Act compliance middleware for AI agents. Make any LLM-powered agent legally deployable in Europe with 3 lines of code.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Sagar-Gogineni/agentguard
|
|
6
|
+
Project-URL: Documentation, https://agentguard.dev
|
|
7
|
+
Project-URL: Repository, https://github.com/Sagar-Gogineni/agentguard
|
|
8
|
+
Project-URL: Issues, https://github.com/Sagar-Gogineni/agentguard/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/Sagar-Gogineni/agentguard/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Sagar
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: ai-agents,ai-compliance,audit,eu-ai-act,governance,llm,middleware,transparency
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: pydantic>=2.0
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: anthropic>=0.30; extra == 'all'
|
|
29
|
+
Requires-Dist: langchain-core>=0.2; extra == 'all'
|
|
30
|
+
Requires-Dist: langchain-openai>=0.1; extra == 'all'
|
|
31
|
+
Requires-Dist: openai>=1.0; extra == 'all'
|
|
32
|
+
Requires-Dist: python-dotenv>=1.0; extra == 'all'
|
|
33
|
+
Requires-Dist: streamlit>=1.30; extra == 'all'
|
|
34
|
+
Provides-Extra: anthropic
|
|
35
|
+
Requires-Dist: anthropic>=0.30; extra == 'anthropic'
|
|
36
|
+
Provides-Extra: dashboard
|
|
37
|
+
Requires-Dist: streamlit>=1.30; extra == 'dashboard'
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
42
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
43
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
44
|
+
Provides-Extra: dotenv
|
|
45
|
+
Requires-Dist: python-dotenv>=1.0; extra == 'dotenv'
|
|
46
|
+
Provides-Extra: langchain
|
|
47
|
+
Requires-Dist: langchain-core>=0.2; extra == 'langchain'
|
|
48
|
+
Requires-Dist: langchain-openai>=0.1; extra == 'langchain'
|
|
49
|
+
Provides-Extra: openai
|
|
50
|
+
Requires-Dist: openai>=1.0; extra == 'openai'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# 🛡️ AgentGuard
|
|
54
|
+
|
|
55
|
+
**EU AI Act compliance middleware for AI agents. Make any LLM-powered agent legally deployable in Europe with 3 lines of code.**
|
|
56
|
+
|
|
57
|
+
[](https://pypi.org/project/agentguard-eu/)
|
|
58
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
59
|
+
[](https://www.python.org/downloads/)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## The Problem
|
|
64
|
+
|
|
65
|
+
Starting **August 2, 2026**, every company deploying AI systems in the EU must comply with the [EU AI Act](https://artificialintelligenceact.eu/) — or face fines up to **€35M or 7% of global turnover**.
|
|
66
|
+
|
|
67
|
+
There are hundreds of AI agent frameworks on GitHub. Almost none of them can be legally deployed in Europe.
|
|
68
|
+
|
|
69
|
+
AgentGuard fixes that. It's a lightweight middleware that wraps any AI agent or LLM call with the compliance layer required by the EU AI Act:
|
|
70
|
+
|
|
71
|
+
| EU AI Act Requirement | Article | AgentGuard Feature |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| Users must know they're talking to AI | Art. 50(1) | Automatic disclosure injection |
|
|
74
|
+
| AI content must be machine-readable labeled | Art. 50(2) | Content labeling (C2PA-compatible) |
|
|
75
|
+
| Interactions must be logged and auditable | Art. 12 | Structured audit logging (file/SQLite) |
|
|
76
|
+
| Human oversight must be possible | Art. 14 | Automatic escalation + review queue |
|
|
77
|
+
| System must be documented | Art. 11, 18 | Auto-generated compliance reports |
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install agentguard-eu
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from agentguard import AgentGuard
|
|
87
|
+
|
|
88
|
+
# 1. Initialize with your system details
|
|
89
|
+
guard = AgentGuard(
|
|
90
|
+
system_name="customer-support-bot",
|
|
91
|
+
provider_name="my-provider",
|
|
92
|
+
risk_level="limited",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# 2. Wrap any LLM function
|
|
96
|
+
result = guard.invoke(
|
|
97
|
+
func=my_llm_function, # Your existing AI function
|
|
98
|
+
input_text="What is your return policy?",
|
|
99
|
+
user_id="customer-42",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# 3. Everything is now compliant
|
|
103
|
+
print(result["response"]) # AI response with disclosure
|
|
104
|
+
print(result["interaction_id"]) # Unique audit trail ID
|
|
105
|
+
print(result["disclosure"]) # HTTP headers for Article 50
|
|
106
|
+
print(result["content_label"]) # Machine-readable content label
|
|
107
|
+
print(result["escalated"]) # Whether human review was triggered
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**That's it.** Your existing AI code doesn't change. AgentGuard wraps it.
|
|
111
|
+
|
|
112
|
+
## Three Ways to Use
|
|
113
|
+
|
|
114
|
+
### 1. `guard.invoke()` — Wrap any function call
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
result = guard.invoke(
|
|
118
|
+
func=lambda q: openai_client.chat.completions.create(
|
|
119
|
+
model="gpt-4", messages=[{"role": "user", "content": q}]
|
|
120
|
+
).choices[0].message.content,
|
|
121
|
+
input_text="Hello!",
|
|
122
|
+
user_id="user-123",
|
|
123
|
+
model="gpt-4",
|
|
124
|
+
confidence=0.92,
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2. `@guard.compliant` — Decorator
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
@guard.compliant(model="gpt-4")
|
|
132
|
+
def ask_support(query: str) -> str:
|
|
133
|
+
return openai_client.chat.completions.create(...).choices[0].message.content
|
|
134
|
+
|
|
135
|
+
result = ask_support("Do you ship internationally?", user_id="user-456")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 3. `guard.interaction()` — Context manager
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
with guard.interaction(user_id="user-789") as ctx:
|
|
142
|
+
response = my_complex_agent.run("Analyze this contract")
|
|
143
|
+
ctx.record(
|
|
144
|
+
input_text="Analyze this contract",
|
|
145
|
+
output_text=response,
|
|
146
|
+
confidence=0.45,
|
|
147
|
+
)
|
|
148
|
+
# Low confidence + keyword "contract" → auto-escalated
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Human Oversight (Article 14)
|
|
152
|
+
|
|
153
|
+
AgentGuard automatically detects when interactions should be reviewed by a human:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
guard = AgentGuard(
|
|
157
|
+
system_name="my-bot",
|
|
158
|
+
provider_name="my-provider",
|
|
159
|
+
human_escalation="low_confidence",
|
|
160
|
+
confidence_threshold=0.7,
|
|
161
|
+
sensitive_keywords=["legal", "medical", "financial advice"],
|
|
162
|
+
block_on_escalation=True, # Block response until human approves
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Check pending reviews
|
|
166
|
+
for review in guard.pending_reviews:
|
|
167
|
+
print(f"Needs review: {review['reason']}")
|
|
168
|
+
|
|
169
|
+
# Approve or reject
|
|
170
|
+
guard.oversight.approve(interaction_id)
|
|
171
|
+
guard.oversight.reject(interaction_id, reason="Inaccurate response")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Compliance Reports (Articles 11, 18)
|
|
175
|
+
|
|
176
|
+
Generate audit documentation with one line:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
# JSON report
|
|
180
|
+
guard.generate_report("compliance_report.json")
|
|
181
|
+
|
|
182
|
+
# Markdown report (for human reading)
|
|
183
|
+
print(guard.generate_report_markdown())
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Reports include: system identification, transparency configuration, human oversight settings, interaction statistics, and escalation history.
|
|
187
|
+
|
|
188
|
+
## Provider Wrappers
|
|
189
|
+
|
|
190
|
+
Zero-effort compliance for popular LLM clients — wrap once, every call is compliant.
|
|
191
|
+
|
|
192
|
+
### OpenAI
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
pip install "agentguard-eu[openai]"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from agentguard import AgentGuard, wrap_openai
|
|
200
|
+
from openai import OpenAI
|
|
201
|
+
|
|
202
|
+
guard = AgentGuard(system_name="my-bot", provider_name="my-provider")
|
|
203
|
+
client = wrap_openai(OpenAI(), guard)
|
|
204
|
+
|
|
205
|
+
# Every call is now compliant — logged, disclosed, escalation-checked
|
|
206
|
+
response = client.chat.completions.create(
|
|
207
|
+
model="gpt-4",
|
|
208
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
209
|
+
)
|
|
210
|
+
print(response.choices[0].message.content) # unchanged
|
|
211
|
+
print(response._agentguard["interaction_id"]) # compliance metadata
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Streaming works too — chunks yield in real-time, compliance runs after the stream completes:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
stream = client.chat.completions.create(
|
|
218
|
+
model="gpt-4",
|
|
219
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
220
|
+
stream=True,
|
|
221
|
+
)
|
|
222
|
+
for chunk in stream:
|
|
223
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
224
|
+
print(chunk.choices[0].delta.content, end="")
|
|
225
|
+
print(stream._agentguard) # available after iteration
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Azure OpenAI
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
pip install "agentguard-eu[openai]"
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from agentguard import AgentGuard, wrap_azure_openai
|
|
236
|
+
from openai import AzureOpenAI
|
|
237
|
+
|
|
238
|
+
guard = AgentGuard(system_name="my-bot", provider_name="my-provider")
|
|
239
|
+
client = wrap_azure_openai(
|
|
240
|
+
AzureOpenAI(
|
|
241
|
+
azure_endpoint="https://my-resource.openai.azure.com",
|
|
242
|
+
api_version="2024-02-01",
|
|
243
|
+
api_key="...",
|
|
244
|
+
),
|
|
245
|
+
guard,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
response = client.chat.completions.create(
|
|
249
|
+
model="my-deployment",
|
|
250
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Anthropic
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
pip install "agentguard-eu[anthropic]"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
from agentguard import AgentGuard, wrap_anthropic
|
|
262
|
+
from anthropic import Anthropic
|
|
263
|
+
|
|
264
|
+
guard = AgentGuard(system_name="my-bot", provider_name="my-provider")
|
|
265
|
+
client = wrap_anthropic(Anthropic(), guard)
|
|
266
|
+
|
|
267
|
+
message = client.messages.create(
|
|
268
|
+
model="claude-sonnet-4-5-20250929",
|
|
269
|
+
max_tokens=1024,
|
|
270
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
271
|
+
)
|
|
272
|
+
print(message.content[0].text) # unchanged
|
|
273
|
+
print(message._agentguard["interaction_id"]) # compliance metadata
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### LangChain
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
pip install "agentguard-eu[langchain]"
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from agentguard import AgentGuard, AgentGuardCallback
|
|
284
|
+
from langchain_openai import ChatOpenAI # or AzureChatOpenAI, ChatAnthropic, etc.
|
|
285
|
+
|
|
286
|
+
guard = AgentGuard(system_name="my-bot", provider_name="my-provider")
|
|
287
|
+
callback = AgentGuardCallback(guard, user_id="user-123")
|
|
288
|
+
llm = ChatOpenAI(model="gpt-4", callbacks=[callback])
|
|
289
|
+
|
|
290
|
+
response = llm.invoke("Hello!")
|
|
291
|
+
print(response.content)
|
|
292
|
+
print(callback.last_result) # compliance metadata for most recent call
|
|
293
|
+
print(callback.results) # all runs keyed by run_id
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Works with any LangChain LLM — ChatOpenAI, AzureChatOpenAI, ChatAnthropic, and more. Streaming is also supported automatically via the callback hooks.
|
|
297
|
+
|
|
298
|
+
## Audit Backends (Article 12)
|
|
299
|
+
|
|
300
|
+
AgentGuard supports multiple audit backends for logging all AI interactions:
|
|
301
|
+
|
|
302
|
+
### File Backend (default)
|
|
303
|
+
|
|
304
|
+
Writes one JSONL file per day to the audit directory. Simple, portable, and easy to ship to external systems:
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
guard = AgentGuard(
|
|
308
|
+
system_name="my-bot",
|
|
309
|
+
provider_name="my-provider",
|
|
310
|
+
audit_backend="file",
|
|
311
|
+
audit_path="./agentguard_audit",
|
|
312
|
+
)
|
|
313
|
+
# Logs go to ./agentguard_audit/audit_2026-02-07.jsonl
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### SQLite Backend
|
|
317
|
+
|
|
318
|
+
Local SQLite database with built-in querying and statistics. Required for the dashboard and compliance report statistics:
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
guard = AgentGuard(
|
|
322
|
+
system_name="my-bot",
|
|
323
|
+
provider_name="my-provider",
|
|
324
|
+
audit_backend="sqlite",
|
|
325
|
+
audit_path="./agentguard_audit",
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
# Query audit logs programmatically
|
|
329
|
+
entries = guard.audit.query(
|
|
330
|
+
start_date="2026-01-01",
|
|
331
|
+
end_date="2026-02-07",
|
|
332
|
+
user_id="customer-42",
|
|
333
|
+
escalated_only=True,
|
|
334
|
+
limit=100,
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
# Get aggregate statistics
|
|
338
|
+
stats = guard.audit.get_stats()
|
|
339
|
+
print(stats)
|
|
340
|
+
# {
|
|
341
|
+
# "total_interactions": 1234,
|
|
342
|
+
# "total_escalations": 56,
|
|
343
|
+
# "total_errors": 3,
|
|
344
|
+
# "disclosures_shown": 1231,
|
|
345
|
+
# "unique_users": 89,
|
|
346
|
+
# "avg_latency_ms": 245.3,
|
|
347
|
+
# }
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Custom Backend
|
|
351
|
+
|
|
352
|
+
Provide your own callback for integration with external logging systems (e.g., S3, BigQuery, Datadog):
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
def my_log_handler(entry):
|
|
356
|
+
# Send to your logging infrastructure
|
|
357
|
+
requests.post("https://my-logging-api/ingest", json=entry.model_dump())
|
|
358
|
+
|
|
359
|
+
guard = AgentGuard(
|
|
360
|
+
system_name="my-bot",
|
|
361
|
+
provider_name="my-provider",
|
|
362
|
+
audit_backend="custom",
|
|
363
|
+
)
|
|
364
|
+
# Pass custom_callback when constructing the AuditLogger directly
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Human Review Dashboard
|
|
368
|
+
|
|
369
|
+
A Streamlit-based dashboard for Article 14 human oversight.
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
pip install "agentguard-eu[dashboard]"
|
|
373
|
+
agentguard-dashboard --audit-path ./agentguard_audit
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Features:
|
|
377
|
+
- Compliance statistics (total interactions, escalation rate, avg confidence, avg latency)
|
|
378
|
+
- Pending escalation review queue with Approve/Reject buttons
|
|
379
|
+
- Full audit log browser with filters (date range, user ID, escalated only)
|
|
380
|
+
- CSV export of audit data
|
|
381
|
+
- Live compliance report viewer
|
|
382
|
+
|
|
383
|
+
Requires the `sqlite` audit backend (`audit_backend="sqlite"`) to be enabled in your AgentGuard configuration. The dashboard connects directly to the SQLite audit database.
|
|
384
|
+
|
|
385
|
+
## FastAPI Integration
|
|
386
|
+
|
|
387
|
+
See [examples/fastapi_example.py](examples/fastapi_example.py) for a complete API with:
|
|
388
|
+
- Compliant `/chat` endpoint with automatic headers
|
|
389
|
+
- `/compliance/report` endpoint
|
|
390
|
+
- `/compliance/pending-reviews` for human oversight
|
|
391
|
+
- Approve/reject endpoints for review queue
|
|
392
|
+
|
|
393
|
+
## Configuration
|
|
394
|
+
|
|
395
|
+
```python
|
|
396
|
+
guard = AgentGuard(
|
|
397
|
+
# Identity (Article 16)
|
|
398
|
+
system_name="my-ai-system",
|
|
399
|
+
provider_name="My Company GmbH",
|
|
400
|
+
risk_level="limited", # "minimal", "limited", or "high"
|
|
401
|
+
intended_purpose="Customer support chatbot",
|
|
402
|
+
|
|
403
|
+
# Transparency (Article 50)
|
|
404
|
+
disclosure_method="metadata", # "prepend", "metadata", or "header"
|
|
405
|
+
label_content=True, # Machine-readable content labels
|
|
406
|
+
|
|
407
|
+
# Audit (Article 12)
|
|
408
|
+
audit_backend="sqlite", # "file", "sqlite", or "custom"
|
|
409
|
+
audit_path="./audit_logs",
|
|
410
|
+
log_inputs=True,
|
|
411
|
+
log_outputs=True,
|
|
412
|
+
retention_days=365,
|
|
413
|
+
|
|
414
|
+
# Human Oversight (Article 14)
|
|
415
|
+
human_escalation="low_confidence", # "never", "low_confidence", "sensitive_topic", "always_review"
|
|
416
|
+
confidence_threshold=0.7,
|
|
417
|
+
sensitive_keywords=["legal", "medical", "financial"],
|
|
418
|
+
escalation_callback=my_slack_notifier, # Optional: get notified
|
|
419
|
+
block_on_escalation=False,
|
|
420
|
+
)
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## What AgentGuard is NOT
|
|
424
|
+
|
|
425
|
+
- ❌ Not a legal compliance guarantee (consult qualified legal professionals)
|
|
426
|
+
- ❌ Not an AI agent framework (use LangGraph, CrewAI, etc. — then wrap with AgentGuard)
|
|
427
|
+
- ❌ Not a replacement for a full conformity assessment (required for high-risk systems)
|
|
428
|
+
- ✅ A practical engineering tool that covers the technical requirements
|
|
429
|
+
|
|
430
|
+
## EU AI Act Timeline
|
|
431
|
+
|
|
432
|
+
| Date | Milestone |
|
|
433
|
+
|------|-----------|
|
|
434
|
+
| Feb 2025 | Prohibited AI practices banned |
|
|
435
|
+
| Aug 2025 | GPAI model rules in effect |
|
|
436
|
+
| **Aug 2026** | **Full enforcement: transparency, high-risk obligations, Article 50** |
|
|
437
|
+
| Aug 2027 | Remaining provisions for product-embedded AI |
|
|
438
|
+
|
|
439
|
+
**AgentGuard targets the August 2026 deadline** — the biggest compliance milestone for most companies.
|
|
440
|
+
|
|
441
|
+
## Contributing
|
|
442
|
+
|
|
443
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
444
|
+
|
|
445
|
+
Priority areas:
|
|
446
|
+
- Cloud audit backends (S3, BigQuery)
|
|
447
|
+
- C2PA standard implementation
|
|
448
|
+
- Async support (ainvoke, async wrappers)
|
|
449
|
+
- Webhook notifications for escalations
|
|
450
|
+
|
|
451
|
+
## License
|
|
452
|
+
|
|
453
|
+
Apache 2.0 — use it freely in commercial projects.
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
**Built by [Sagar](https://github.com/Sagar-Gogineni)** — AI Engineer based in Berlin, specializing in enterprise AI systems and compliance.
|
|
458
|
+
|
|
459
|
+
*AgentGuard: Because shipping AI agents without compliance is like shipping code without tests. You can do it, but you probably shouldn't.*
|