agentaudit-client 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.
- agentaudit_client-1.0.0/PKG-INFO +173 -0
- agentaudit_client-1.0.0/README.md +135 -0
- agentaudit_client-1.0.0/agentaudit/__init__.py +252 -0
- agentaudit_client-1.0.0/agentaudit_client.egg-info/PKG-INFO +173 -0
- agentaudit_client-1.0.0/agentaudit_client.egg-info/SOURCES.txt +8 -0
- agentaudit_client-1.0.0/agentaudit_client.egg-info/dependency_links.txt +1 -0
- agentaudit_client-1.0.0/agentaudit_client.egg-info/requires.txt +9 -0
- agentaudit_client-1.0.0/agentaudit_client.egg-info/top_level.txt +1 -0
- agentaudit_client-1.0.0/setup.cfg +4 -0
- agentaudit_client-1.0.0/setup.py +33 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentaudit-client
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Audit & Compliance SDK for AI Agents
|
|
5
|
+
Home-page: https://github.com/agentaudit/agentaudit-python
|
|
6
|
+
Author: AgentAudit Team
|
|
7
|
+
Author-email: support@agentaudit.io
|
|
8
|
+
Keywords: ai agents audit compliance langchain monitoring
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: requests>=2.25.0
|
|
21
|
+
Provides-Extra: langchain
|
|
22
|
+
Requires-Dist: langchain>=0.1.0; extra == "langchain"
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: black; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy; extra == "dev"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: author-email
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: keywords
|
|
34
|
+
Dynamic: provides-extra
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# AgentAudit Python SDK
|
|
40
|
+
|
|
41
|
+
Official Python SDK for the AgentAudit API — audit logging and compliance monitoring for AI agents.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install agentaudit-client
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With LangChain support:
|
|
50
|
+
```bash
|
|
51
|
+
pip install agentaudit-client[langchain]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from agentaudit import AgentAudit
|
|
58
|
+
|
|
59
|
+
# Initialize
|
|
60
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
61
|
+
|
|
62
|
+
# Log an agent action
|
|
63
|
+
audit.log(
|
|
64
|
+
action="prompt_submitted",
|
|
65
|
+
prompt="What is the weather?",
|
|
66
|
+
response="It is sunny today.",
|
|
67
|
+
metadata={"model": "gpt-4", "tokens": 150}
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## LangChain Integration
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from langchain.callbacks import AgentAuditCallbackHandler
|
|
75
|
+
from langchain.llms import OpenAI
|
|
76
|
+
|
|
77
|
+
# Setup audit callback
|
|
78
|
+
audit_handler = AgentAuditCallbackHandler(
|
|
79
|
+
api_key="aa_your_key_here",
|
|
80
|
+
agent_id="uuid-of-your-agent"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Use with any LangChain component
|
|
84
|
+
llm = OpenAI(callbacks=[audit_handler])
|
|
85
|
+
llm.predict("What is the weather?")
|
|
86
|
+
# Automatically logged to AgentAudit!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Features
|
|
90
|
+
|
|
91
|
+
- **Simple logging**: One-line audit log submission
|
|
92
|
+
- **Automatic compliance**: PII detection, keyword matching, rate limiting, regex matching, sentiment analysis, custom validators
|
|
93
|
+
- **Agent registration**: Track which agents are performing actions
|
|
94
|
+
- **Query and export**: Retrieve audit logs with filters
|
|
95
|
+
- **LangChain support**: Drop-in callback handler
|
|
96
|
+
- **Type hints**: Full type annotation support
|
|
97
|
+
|
|
98
|
+
## Agent-to-Agent Audit Trails
|
|
99
|
+
|
|
100
|
+
Track multi-agent conversations and CrewAI workflows with distributed tracing:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import uuid
|
|
104
|
+
from agentaudit import AgentAudit
|
|
105
|
+
|
|
106
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
107
|
+
|
|
108
|
+
# Start a trace — e.g. when a CrewAI crew begins execution
|
|
109
|
+
trace_id = str(uuid.uuid4())
|
|
110
|
+
|
|
111
|
+
# Log the root event (crew start)
|
|
112
|
+
root = audit.log(
|
|
113
|
+
action="crewai_crew_start",
|
|
114
|
+
trace_id=trace_id,
|
|
115
|
+
metadata={"crew": "Research Crew", "task_count": 3}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Log child events (tasks, agent actions) with parent_span_id
|
|
119
|
+
audit.log(
|
|
120
|
+
action="crewai_task_start",
|
|
121
|
+
trace_id=trace_id,
|
|
122
|
+
parent_span_id=root.id,
|
|
123
|
+
prompt="Research topic X",
|
|
124
|
+
metadata={"task_id": "task-1"}
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Query the full trace later
|
|
128
|
+
# (use the HTTP client or dashboard to query by traceId)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### CrewAI Integration
|
|
132
|
+
|
|
133
|
+
The [CrewAI observer](../../integrations/crewai/) automatically manages trace IDs and parent span IDs:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from agentaudit_crewai import AgentAuditObserver
|
|
137
|
+
|
|
138
|
+
observer = AgentAuditObserver(api_key="aa_key", crew_name="My Crew")
|
|
139
|
+
# trace_id is generated automatically in on_crew_start
|
|
140
|
+
# every event shares the same trace_id with proper parent_span_id linking
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Documentation
|
|
144
|
+
|
|
145
|
+
Full API documentation: https://docs.agentaudit.io
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Publishing (Maintainers Only)
|
|
154
|
+
|
|
155
|
+
This package is published automatically via GitHub Actions when you push a version tag:
|
|
156
|
+
|
|
157
|
+
### Prerequisites
|
|
158
|
+
1. Create a [PyPI account](https://pypi.org/account/register/)
|
|
159
|
+
2. Generate an API token at [pypi.org/manage/account/token](https://pypi.org/manage/account/token)
|
|
160
|
+
3. Add the token to your GitHub repo: **Settings → Secrets and variables → Actions → New repository secret**
|
|
161
|
+
- Name: `PYPI_API_TOKEN`
|
|
162
|
+
- Value: your PyPI API token (starts with `pypi-`)
|
|
163
|
+
|
|
164
|
+
### Publish a New Version
|
|
165
|
+
```bash
|
|
166
|
+
# Update version in sdk/python/setup.py
|
|
167
|
+
git add sdk/python/setup.py
|
|
168
|
+
git commit -m "chore: bump Python SDK to v1.0.1"
|
|
169
|
+
git tag v1.0.1
|
|
170
|
+
git push origin v1.0.1
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The `publish-python.yml` workflow will automatically build and upload to PyPI.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# AgentAudit Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for the AgentAudit API — audit logging and compliance monitoring for AI agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install agentaudit-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
With LangChain support:
|
|
12
|
+
```bash
|
|
13
|
+
pip install agentaudit-client[langchain]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from agentaudit import AgentAudit
|
|
20
|
+
|
|
21
|
+
# Initialize
|
|
22
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
23
|
+
|
|
24
|
+
# Log an agent action
|
|
25
|
+
audit.log(
|
|
26
|
+
action="prompt_submitted",
|
|
27
|
+
prompt="What is the weather?",
|
|
28
|
+
response="It is sunny today.",
|
|
29
|
+
metadata={"model": "gpt-4", "tokens": 150}
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## LangChain Integration
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from langchain.callbacks import AgentAuditCallbackHandler
|
|
37
|
+
from langchain.llms import OpenAI
|
|
38
|
+
|
|
39
|
+
# Setup audit callback
|
|
40
|
+
audit_handler = AgentAuditCallbackHandler(
|
|
41
|
+
api_key="aa_your_key_here",
|
|
42
|
+
agent_id="uuid-of-your-agent"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Use with any LangChain component
|
|
46
|
+
llm = OpenAI(callbacks=[audit_handler])
|
|
47
|
+
llm.predict("What is the weather?")
|
|
48
|
+
# Automatically logged to AgentAudit!
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **Simple logging**: One-line audit log submission
|
|
54
|
+
- **Automatic compliance**: PII detection, keyword matching, rate limiting, regex matching, sentiment analysis, custom validators
|
|
55
|
+
- **Agent registration**: Track which agents are performing actions
|
|
56
|
+
- **Query and export**: Retrieve audit logs with filters
|
|
57
|
+
- **LangChain support**: Drop-in callback handler
|
|
58
|
+
- **Type hints**: Full type annotation support
|
|
59
|
+
|
|
60
|
+
## Agent-to-Agent Audit Trails
|
|
61
|
+
|
|
62
|
+
Track multi-agent conversations and CrewAI workflows with distributed tracing:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import uuid
|
|
66
|
+
from agentaudit import AgentAudit
|
|
67
|
+
|
|
68
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
69
|
+
|
|
70
|
+
# Start a trace — e.g. when a CrewAI crew begins execution
|
|
71
|
+
trace_id = str(uuid.uuid4())
|
|
72
|
+
|
|
73
|
+
# Log the root event (crew start)
|
|
74
|
+
root = audit.log(
|
|
75
|
+
action="crewai_crew_start",
|
|
76
|
+
trace_id=trace_id,
|
|
77
|
+
metadata={"crew": "Research Crew", "task_count": 3}
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Log child events (tasks, agent actions) with parent_span_id
|
|
81
|
+
audit.log(
|
|
82
|
+
action="crewai_task_start",
|
|
83
|
+
trace_id=trace_id,
|
|
84
|
+
parent_span_id=root.id,
|
|
85
|
+
prompt="Research topic X",
|
|
86
|
+
metadata={"task_id": "task-1"}
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Query the full trace later
|
|
90
|
+
# (use the HTTP client or dashboard to query by traceId)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### CrewAI Integration
|
|
94
|
+
|
|
95
|
+
The [CrewAI observer](../../integrations/crewai/) automatically manages trace IDs and parent span IDs:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from agentaudit_crewai import AgentAuditObserver
|
|
99
|
+
|
|
100
|
+
observer = AgentAuditObserver(api_key="aa_key", crew_name="My Crew")
|
|
101
|
+
# trace_id is generated automatically in on_crew_start
|
|
102
|
+
# every event shares the same trace_id with proper parent_span_id linking
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
Full API documentation: https://docs.agentaudit.io
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Publishing (Maintainers Only)
|
|
116
|
+
|
|
117
|
+
This package is published automatically via GitHub Actions when you push a version tag:
|
|
118
|
+
|
|
119
|
+
### Prerequisites
|
|
120
|
+
1. Create a [PyPI account](https://pypi.org/account/register/)
|
|
121
|
+
2. Generate an API token at [pypi.org/manage/account/token](https://pypi.org/manage/account/token)
|
|
122
|
+
3. Add the token to your GitHub repo: **Settings → Secrets and variables → Actions → New repository secret**
|
|
123
|
+
- Name: `PYPI_API_TOKEN`
|
|
124
|
+
- Value: your PyPI API token (starts with `pypi-`)
|
|
125
|
+
|
|
126
|
+
### Publish a New Version
|
|
127
|
+
```bash
|
|
128
|
+
# Update version in sdk/python/setup.py
|
|
129
|
+
git add sdk/python/setup.py
|
|
130
|
+
git commit -m "chore: bump Python SDK to v1.0.1"
|
|
131
|
+
git tag v1.0.1
|
|
132
|
+
git push origin v1.0.1
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The `publish-python.yml` workflow will automatically build and upload to PyPI.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AgentAudit Python SDK
|
|
3
|
+
Drop-in audit logging for AI agents.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
from typing import Optional, Dict, Any, List
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class AuditLog:
|
|
13
|
+
"""Represents an audit log entry."""
|
|
14
|
+
id: str
|
|
15
|
+
action: str
|
|
16
|
+
agent_id: Optional[str]
|
|
17
|
+
prompt: Optional[str]
|
|
18
|
+
response: Optional[str]
|
|
19
|
+
metadata: Optional[Dict[str, Any]]
|
|
20
|
+
compliance_flags: List[str]
|
|
21
|
+
created_at: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class GuardrailResult:
|
|
26
|
+
"""Result of a compliance guardrail check."""
|
|
27
|
+
allowed: bool
|
|
28
|
+
action: str
|
|
29
|
+
violations: List[str]
|
|
30
|
+
severity: str
|
|
31
|
+
audit_log_id: Optional[str] = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AgentAudit:
|
|
35
|
+
"""
|
|
36
|
+
AgentAudit client for submitting audit logs and managing agents.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
api_key: str,
|
|
42
|
+
base_url: str = "https://agentaudit-api-production.up.railway.app/api/v1",
|
|
43
|
+
agent_id: Optional[str] = None
|
|
44
|
+
):
|
|
45
|
+
self.api_key = api_key
|
|
46
|
+
self.base_url = base_url.rstrip("/")
|
|
47
|
+
self.agent_id = agent_id
|
|
48
|
+
self.session = requests.Session()
|
|
49
|
+
self.session.headers.update({
|
|
50
|
+
"X-API-Key": api_key,
|
|
51
|
+
"Content-Type": "application/json"
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
def guardrail(
|
|
55
|
+
self,
|
|
56
|
+
action: str,
|
|
57
|
+
prompt: Optional[str] = None,
|
|
58
|
+
response: Optional[str] = None,
|
|
59
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
60
|
+
agent_id: Optional[str] = None,
|
|
61
|
+
trace_id: Optional[str] = None,
|
|
62
|
+
parent_span_id: Optional[str] = None
|
|
63
|
+
) -> GuardrailResult:
|
|
64
|
+
"""
|
|
65
|
+
Real-time compliance check. Intercepts agent output before delivery.
|
|
66
|
+
|
|
67
|
+
Usage:
|
|
68
|
+
result = audit.guardrail(
|
|
69
|
+
action="prompt_submitted",
|
|
70
|
+
prompt=user_input,
|
|
71
|
+
response=agent_output
|
|
72
|
+
)
|
|
73
|
+
if not result.allowed:
|
|
74
|
+
raise ValueError(f"Blocked: {result.violations}")
|
|
75
|
+
"""
|
|
76
|
+
payload = {
|
|
77
|
+
"action": action,
|
|
78
|
+
"agentId": agent_id or self.agent_id,
|
|
79
|
+
"checkType": "realtime"
|
|
80
|
+
}
|
|
81
|
+
if prompt:
|
|
82
|
+
payload["prompt"] = prompt
|
|
83
|
+
if response:
|
|
84
|
+
payload["response"] = response
|
|
85
|
+
if metadata:
|
|
86
|
+
payload["metadata"] = metadata
|
|
87
|
+
if trace_id:
|
|
88
|
+
payload["traceId"] = trace_id
|
|
89
|
+
if parent_span_id:
|
|
90
|
+
payload["parentSpanId"] = parent_span_id
|
|
91
|
+
|
|
92
|
+
resp = self.session.post(
|
|
93
|
+
f"{self.base_url}/audit-logs",
|
|
94
|
+
json=payload
|
|
95
|
+
)
|
|
96
|
+
resp.raise_for_status()
|
|
97
|
+
data = resp.json()
|
|
98
|
+
|
|
99
|
+
flags = data.get("complianceFlags", [])
|
|
100
|
+
severity = "critical" if any("PII" in f or "block" in f.lower() for f in flags) else "warning"
|
|
101
|
+
action_result = "block" if severity == "critical" and flags else ("flag" if flags else "allow")
|
|
102
|
+
|
|
103
|
+
return GuardrailResult(
|
|
104
|
+
allowed=action_result != "block",
|
|
105
|
+
action=action_result,
|
|
106
|
+
violations=flags,
|
|
107
|
+
severity=severity,
|
|
108
|
+
audit_log_id=data.get("id")
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def log(
|
|
112
|
+
self,
|
|
113
|
+
action: str,
|
|
114
|
+
prompt: Optional[str] = None,
|
|
115
|
+
response: Optional[str] = None,
|
|
116
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
117
|
+
agent_id: Optional[str] = None,
|
|
118
|
+
trace_id: Optional[str] = None,
|
|
119
|
+
parent_span_id: Optional[str] = None
|
|
120
|
+
) -> AuditLog:
|
|
121
|
+
"""
|
|
122
|
+
Submit an audit log entry.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
action: The action performed (e.g., "prompt_submitted", "tool_executed")
|
|
126
|
+
prompt: The input prompt (optional)
|
|
127
|
+
response: The output response (optional)
|
|
128
|
+
metadata: Additional structured data (optional)
|
|
129
|
+
agent_id: Override the default agent ID (optional)
|
|
130
|
+
trace_id: Trace ID for agent-to-agent audit trails (optional)
|
|
131
|
+
parent_span_id: Parent span ID for chain tracking (optional)
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
AuditLog: The created audit log entry
|
|
135
|
+
"""
|
|
136
|
+
payload = {
|
|
137
|
+
"action": action,
|
|
138
|
+
"agentId": agent_id or self.agent_id,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if prompt is not None:
|
|
142
|
+
payload["prompt"] = prompt
|
|
143
|
+
if response is not None:
|
|
144
|
+
payload["response"] = response
|
|
145
|
+
if metadata is not None:
|
|
146
|
+
payload["metadata"] = metadata
|
|
147
|
+
if trace_id is not None:
|
|
148
|
+
payload["traceId"] = trace_id
|
|
149
|
+
if parent_span_id is not None:
|
|
150
|
+
payload["parentSpanId"] = parent_span_id
|
|
151
|
+
|
|
152
|
+
resp = self.session.post(
|
|
153
|
+
f"{self.base_url}/audit-logs",
|
|
154
|
+
json=payload
|
|
155
|
+
)
|
|
156
|
+
resp.raise_for_status()
|
|
157
|
+
data = resp.json()
|
|
158
|
+
|
|
159
|
+
return AuditLog(
|
|
160
|
+
id=data["id"],
|
|
161
|
+
action=data["action"],
|
|
162
|
+
agent_id=data.get("agentId"),
|
|
163
|
+
prompt=data.get("prompt"),
|
|
164
|
+
response=data.get("response"),
|
|
165
|
+
metadata=data.get("metadata"),
|
|
166
|
+
compliance_flags=data.get("complianceFlags", []),
|
|
167
|
+
created_at=data["createdAt"]
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def register_agent(
|
|
171
|
+
self,
|
|
172
|
+
name: str,
|
|
173
|
+
agent_type: str = "custom",
|
|
174
|
+
description: Optional[str] = None,
|
|
175
|
+
config: Optional[Dict[str, Any]] = None
|
|
176
|
+
) -> Dict[str, Any]:
|
|
177
|
+
"""Register a new agent and return its ID."""
|
|
178
|
+
payload = {
|
|
179
|
+
"name": name,
|
|
180
|
+
"type": agent_type,
|
|
181
|
+
}
|
|
182
|
+
if description:
|
|
183
|
+
payload["description"] = description
|
|
184
|
+
if config:
|
|
185
|
+
payload["config"] = config
|
|
186
|
+
|
|
187
|
+
resp = self.session.post(
|
|
188
|
+
f"{self.base_url}/agents",
|
|
189
|
+
json=payload
|
|
190
|
+
)
|
|
191
|
+
resp.raise_for_status()
|
|
192
|
+
return resp.json()
|
|
193
|
+
|
|
194
|
+
def query_logs(
|
|
195
|
+
self,
|
|
196
|
+
action: Optional[str] = None,
|
|
197
|
+
agent_id: Optional[str] = None,
|
|
198
|
+
start_date: Optional[str] = None,
|
|
199
|
+
end_date: Optional[str] = None,
|
|
200
|
+
page: int = 1,
|
|
201
|
+
limit: int = 20
|
|
202
|
+
) -> Dict[str, Any]:
|
|
203
|
+
"""Query audit logs with filters."""
|
|
204
|
+
params = {"page": page, "limit": limit}
|
|
205
|
+
if action:
|
|
206
|
+
params["action"] = action
|
|
207
|
+
if agent_id:
|
|
208
|
+
params["agentId"] = agent_id
|
|
209
|
+
if start_date:
|
|
210
|
+
params["startDate"] = start_date
|
|
211
|
+
if end_date:
|
|
212
|
+
params["endDate"] = end_date
|
|
213
|
+
|
|
214
|
+
resp = self.session.get(
|
|
215
|
+
f"{self.base_url}/audit-logs",
|
|
216
|
+
params=params
|
|
217
|
+
)
|
|
218
|
+
resp.raise_for_status()
|
|
219
|
+
return resp.json()
|
|
220
|
+
|
|
221
|
+
def get_alerts(
|
|
222
|
+
self,
|
|
223
|
+
is_resolved: Optional[bool] = None,
|
|
224
|
+
severity: Optional[str] = None
|
|
225
|
+
) -> List[Dict[str, Any]]:
|
|
226
|
+
"""Get compliance alerts."""
|
|
227
|
+
params = {}
|
|
228
|
+
if is_resolved is not None:
|
|
229
|
+
params["isResolved"] = str(is_resolved).lower()
|
|
230
|
+
if severity:
|
|
231
|
+
params["severity"] = severity
|
|
232
|
+
|
|
233
|
+
resp = self.session.get(
|
|
234
|
+
f"{self.base_url}/alerts",
|
|
235
|
+
params=params
|
|
236
|
+
)
|
|
237
|
+
resp.raise_for_status()
|
|
238
|
+
return resp.json()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class AgentAuditCallback:
|
|
242
|
+
"""
|
|
243
|
+
Callback-style integration for frameworks that support callbacks.
|
|
244
|
+
Automatically logs all agent actions.
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
def __init__(self, api_key: str, agent_id: Optional[str] = None):
|
|
248
|
+
self.client = AgentAudit(api_key=api_key, agent_id=agent_id)
|
|
249
|
+
|
|
250
|
+
def on_action(self, action: str, **kwargs):
|
|
251
|
+
"""Log an action with optional prompt/response/metadata."""
|
|
252
|
+
return self.client.log(action=action, **kwargs)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentaudit-client
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Audit & Compliance SDK for AI Agents
|
|
5
|
+
Home-page: https://github.com/agentaudit/agentaudit-python
|
|
6
|
+
Author: AgentAudit Team
|
|
7
|
+
Author-email: support@agentaudit.io
|
|
8
|
+
Keywords: ai agents audit compliance langchain monitoring
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: requests>=2.25.0
|
|
21
|
+
Provides-Extra: langchain
|
|
22
|
+
Requires-Dist: langchain>=0.1.0; extra == "langchain"
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: black; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy; extra == "dev"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: author-email
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: keywords
|
|
34
|
+
Dynamic: provides-extra
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# AgentAudit Python SDK
|
|
40
|
+
|
|
41
|
+
Official Python SDK for the AgentAudit API — audit logging and compliance monitoring for AI agents.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install agentaudit-client
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With LangChain support:
|
|
50
|
+
```bash
|
|
51
|
+
pip install agentaudit-client[langchain]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from agentaudit import AgentAudit
|
|
58
|
+
|
|
59
|
+
# Initialize
|
|
60
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
61
|
+
|
|
62
|
+
# Log an agent action
|
|
63
|
+
audit.log(
|
|
64
|
+
action="prompt_submitted",
|
|
65
|
+
prompt="What is the weather?",
|
|
66
|
+
response="It is sunny today.",
|
|
67
|
+
metadata={"model": "gpt-4", "tokens": 150}
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## LangChain Integration
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from langchain.callbacks import AgentAuditCallbackHandler
|
|
75
|
+
from langchain.llms import OpenAI
|
|
76
|
+
|
|
77
|
+
# Setup audit callback
|
|
78
|
+
audit_handler = AgentAuditCallbackHandler(
|
|
79
|
+
api_key="aa_your_key_here",
|
|
80
|
+
agent_id="uuid-of-your-agent"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Use with any LangChain component
|
|
84
|
+
llm = OpenAI(callbacks=[audit_handler])
|
|
85
|
+
llm.predict("What is the weather?")
|
|
86
|
+
# Automatically logged to AgentAudit!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Features
|
|
90
|
+
|
|
91
|
+
- **Simple logging**: One-line audit log submission
|
|
92
|
+
- **Automatic compliance**: PII detection, keyword matching, rate limiting, regex matching, sentiment analysis, custom validators
|
|
93
|
+
- **Agent registration**: Track which agents are performing actions
|
|
94
|
+
- **Query and export**: Retrieve audit logs with filters
|
|
95
|
+
- **LangChain support**: Drop-in callback handler
|
|
96
|
+
- **Type hints**: Full type annotation support
|
|
97
|
+
|
|
98
|
+
## Agent-to-Agent Audit Trails
|
|
99
|
+
|
|
100
|
+
Track multi-agent conversations and CrewAI workflows with distributed tracing:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import uuid
|
|
104
|
+
from agentaudit import AgentAudit
|
|
105
|
+
|
|
106
|
+
audit = AgentAudit(api_key="aa_your_key_here")
|
|
107
|
+
|
|
108
|
+
# Start a trace — e.g. when a CrewAI crew begins execution
|
|
109
|
+
trace_id = str(uuid.uuid4())
|
|
110
|
+
|
|
111
|
+
# Log the root event (crew start)
|
|
112
|
+
root = audit.log(
|
|
113
|
+
action="crewai_crew_start",
|
|
114
|
+
trace_id=trace_id,
|
|
115
|
+
metadata={"crew": "Research Crew", "task_count": 3}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Log child events (tasks, agent actions) with parent_span_id
|
|
119
|
+
audit.log(
|
|
120
|
+
action="crewai_task_start",
|
|
121
|
+
trace_id=trace_id,
|
|
122
|
+
parent_span_id=root.id,
|
|
123
|
+
prompt="Research topic X",
|
|
124
|
+
metadata={"task_id": "task-1"}
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Query the full trace later
|
|
128
|
+
# (use the HTTP client or dashboard to query by traceId)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### CrewAI Integration
|
|
132
|
+
|
|
133
|
+
The [CrewAI observer](../../integrations/crewai/) automatically manages trace IDs and parent span IDs:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from agentaudit_crewai import AgentAuditObserver
|
|
137
|
+
|
|
138
|
+
observer = AgentAuditObserver(api_key="aa_key", crew_name="My Crew")
|
|
139
|
+
# trace_id is generated automatically in on_crew_start
|
|
140
|
+
# every event shares the same trace_id with proper parent_span_id linking
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Documentation
|
|
144
|
+
|
|
145
|
+
Full API documentation: https://docs.agentaudit.io
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Publishing (Maintainers Only)
|
|
154
|
+
|
|
155
|
+
This package is published automatically via GitHub Actions when you push a version tag:
|
|
156
|
+
|
|
157
|
+
### Prerequisites
|
|
158
|
+
1. Create a [PyPI account](https://pypi.org/account/register/)
|
|
159
|
+
2. Generate an API token at [pypi.org/manage/account/token](https://pypi.org/manage/account/token)
|
|
160
|
+
3. Add the token to your GitHub repo: **Settings → Secrets and variables → Actions → New repository secret**
|
|
161
|
+
- Name: `PYPI_API_TOKEN`
|
|
162
|
+
- Value: your PyPI API token (starts with `pypi-`)
|
|
163
|
+
|
|
164
|
+
### Publish a New Version
|
|
165
|
+
```bash
|
|
166
|
+
# Update version in sdk/python/setup.py
|
|
167
|
+
git add sdk/python/setup.py
|
|
168
|
+
git commit -m "chore: bump Python SDK to v1.0.1"
|
|
169
|
+
git tag v1.0.1
|
|
170
|
+
git push origin v1.0.1
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The `publish-python.yml` workflow will automatically build and upload to PyPI.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
agentaudit
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="agentaudit-client",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
description="Audit \u0026 Compliance SDK for AI Agents",
|
|
7
|
+
long_description=open("README.md").read(),
|
|
8
|
+
long_description_content_type="text/markdown",
|
|
9
|
+
author="AgentAudit Team",
|
|
10
|
+
author_email="support@agentaudit.io",
|
|
11
|
+
url="https://github.com/agentaudit/agentaudit-python",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
install_requires=[
|
|
14
|
+
"requests>=2.25.0",
|
|
15
|
+
],
|
|
16
|
+
extras_require={
|
|
17
|
+
"langchain": ["langchain>=0.1.0"],
|
|
18
|
+
"dev": ["pytest>=7.0", "black", "mypy"],
|
|
19
|
+
},
|
|
20
|
+
python_requires=">=3.8",
|
|
21
|
+
classifiers=[
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.8",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
],
|
|
32
|
+
keywords="ai agents audit compliance langchain monitoring",
|
|
33
|
+
)
|