AgentAudit Python SDK
Official Python SDK for the AgentAudit API — audit logging and compliance monitoring for AI agents.
Installation
pip install agentaudit-client
With LangChain support:
pip install agentaudit-client[langchain]
Quick Start
from agentaudit import AgentAudit
# Initialize
audit = AgentAudit(api_key="aa_your_key_here")
# Log an agent action
audit.log(
action="prompt_submitted",
prompt="What is the weather?",
response="It is sunny today.",
metadata={"model": "gpt-4", "tokens": 150}
)
LangChain Integration
pip install agentaudit-client[langchain]
from agentaudit import AgentAuditCallbackHandler
from langchain_openai import ChatOpenAI
audit_handler = AgentAuditCallbackHandler(
api_key="aa_your_key_here",
agent_id="uuid-of-your-agent",
guard=True # default
)
# Use with any LangChain component
llm = ChatOpenAI(model="gpt-4o", callbacks=[audit_handler])
llm.invoke("What is the weather?")
# Automatically logged + guarded to AgentAudit!
Async chains and agents
Use AgentAuditAsyncCallbackHandler with ainvoke so API calls do not
block the event loop:
from agentaudit import AgentAuditAsyncCallbackHandler
from langchain_openai import ChatOpenAI
handler = AgentAuditAsyncCallbackHandler(
api_key="aa_your_key_here",
agent_id="uuid-of-your-agent",
guard=True,
)
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])
await llm.ainvoke("What is the weather?")
print(handler.trace_id)
OpenAI Integration
pip install agentaudit-client[openai]
from agentaudit import AgentAuditOpenAI
client = AgentAuditOpenAI(
openai_api_key="sk-...",
api_key="aa_your_key_here",
agent_id="uuid-of-your-agent",
guard=True, # default
)
response = client.chat_completions_create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is the weather?"}]
)
# Automatically logged + guarded!
print(client.trace_id)
AutoGPT Integration
from agentaudit import AgentAuditAutoGPT
logger = AgentAuditAutoGPT(
api_key="aa_your_key_here",
agent_name="MyAutoGPT",
guard=True,
)
with logger.trace() as trace:
result = agent.run("Research topic X")
trace.log_action("run", prompt="Research topic X", response=result)
print(trace.trace_id)
Decorator
from agentaudit import AgentAuditAutoGPT, ComplianceViolationAutoGPT
@AgentAuditAutoGPT.guard(api_key="aa_your_key_here", agent_name="MyAutoGPT")
def run_agent(task: str) -> str:
return agent.run(task)
try:
result = run_agent("Research topic X")
except ComplianceViolationAutoGPT as e:
print(f"Blocked: {e.violations}")
Features
- Simple logging: One-line audit log submission
- Automatic compliance: PII detection, keyword matching, rate limiting, regex matching, sentiment analysis, custom validators
- Agent registration: Track which agents are performing actions
- Query and export: Retrieve audit logs with filters
- LangChain support: Drop-in callback handler
- Type hints: Full type annotation support
Agent-to-Agent Audit Trails
Track multi-agent conversations and CrewAI workflows with distributed tracing:
import uuid
from agentaudit import AgentAudit
audit = AgentAudit(api_key="aa_your_key_here")
# Start a trace — e.g. when a CrewAI crew begins execution
trace_id = str(uuid.uuid4())
# Log the root event (crew start)
root = audit.log(
action="crewai_crew_start",
trace_id=trace_id,
metadata={"crew": "Research Crew", "task_count": 3}
)
# Log child events (tasks, agent actions) with parent_span_id
audit.log(
action="crewai_task_start",
trace_id=trace_id,
parent_span_id=root.id,
prompt="Research topic X",
metadata={"task_id": "task-1"}
)
# Query the full trace later
# (use the HTTP client or dashboard to query by traceId)
CrewAI Integration
The CrewAI observer (agentaudit.crewai) automatically manages trace IDs and parent span IDs:
from agentaudit import AgentAuditObserver
observer = AgentAuditObserver(api_key="aa_key", crew_name="My Crew")
# trace_id is generated automatically in on_crew_start
# every event shares the same trace_id with proper parent_span_id linking
Documentation
Full API documentation: https://agentaudit.online/docs
License
MIT
Publishing (Maintainers Only)
This package is published automatically via GitHub Actions when you push a version tag:
Prerequisites
- Create a PyPI account
- Generate an API token at pypi.org/manage/account/token
- Add the token to your GitHub repo: Settings → Secrets and variables → Actions → New repository secret
- Name:
PYPI_API_TOKEN - Value: your PyPI API token (starts with
pypi-)
- Name:
Publish a New Version
# Update version in sdk/python/setup.py
git add sdk/python/setup.py
git commit -m "chore: bump Python SDK to v1.0.1"
git tag v1.0.1
git push origin v1.0.1
The publish-python.yml workflow will automatically build and upload to PyPI.
Metadata
Release files for agentaudit-client 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| agentaudit_client-1.0.5.tar.gz | 18.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentaudit_client-1.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.8 kB
Release files / agentaudit_client-1.0.5.tar.gz
| Download URL | agentaudit_client-1.0.5.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e36f4f7c6fde0acfb5f9127500bf8115a0797e57a0e1bd9d1ddb14d49b99903
|
|
BLAKE2b-256 checksum How to use checksums |
04c77c510d0323af3d868e6b490dfcac3e0b5c428f7f327762288458c76c97e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / agentaudit_client-1.0.5-py3-none-any.whl
| Download URL | agentaudit_client-1.0.5-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
672eda9ebd6e76582504c18a449ff2692a642b7fb50ec0946f39766bbf0d79be
|
|
BLAKE2b-256 checksum How to use checksums |
57039a438ea02104882c84746f878eff58c66c3e1bff35b92d14c5099a2ab76f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for agentaudit-client 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.