AgentGuard Python SDK
The official Python SDK for AgentGuard Pro - Enterprise AI governance and compliance platform.
🚀 One-Line Integration
Transform your AI infrastructure with a single line of code:
from agentguard import AgentGuard
# Initialize once
agentguard = AgentGuard(tenant_id="your-tenant")
# Before: Complex manual compliance
response = openai.ChatCompletion.create(model="gpt-4", messages=[...])
# After: Automatic compliance with intercept()
response = agentguard.intercept(
openai.ChatCompletion.create,
model="gpt-4",
messages=[...]
)
That's it! The intercept() method automatically handles:
- ✅ Authorization checks
- ✅ Provider detection
- ✅ Context extraction
- ✅ Audit logging
- ✅ Error handling
Installation
pip install agentguard
Quick Start
1. Set up your environment
export AGENTGUARD_API_KEY="your-api-key"
export AGENTGUARD_TENANT_ID="your-tenant-id"
2. Use with any AI provider
from agentguard import AgentGuard
import openai
# Initialize AgentGuard
agentguard = AgentGuard()
# Intercept any AI call
response = agentguard.intercept(
openai.ChatCompletion.create,
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
Supported Providers
The SDK automatically detects and supports:
- ✅ OpenAI (GPT-4, GPT-3.5, DALL-E, etc.)
- ✅ Anthropic (Claude)
- ✅ Azure OpenAI
- ✅ Custom providers (via registration)
Advanced Usage
Custom Provider Registration
# Register your custom AI provider
agentguard.register_provider(
name='custom-llm',
detect_fn=lambda fn, args, kwargs: 'custom' in str(fn),
extract_model_fn=lambda fn, args, kwargs: kwargs.get('model', 'custom'),
extract_context_fn=lambda fn, args, kwargs: {'custom': True},
resource='ai:custom'
)
# Now intercept() works with your custom provider!
response = agentguard.intercept(custom_llm.generate, prompt="Hello")
Error Handling
from agentguard import AgentGuardError
try:
response = agentguard.intercept(
openai.ChatCompletion.create,
model="gpt-4",
messages=[{"role": "user", "content": "Sensitive request"}]
)
except AgentGuardError as e:
if e.code == 'AGENTGUARD_ACCESS_DENIED':
print(f"Access denied: {e}")
# Handle authorization failure
Direct Authorization (Advanced)
# For fine-grained control, use authorize() directly
auth_result = agentguard.authorize(
subject="user@example.com",
resource="ai:gpt-4",
action="generate",
context={"purpose": "customer_support"}
)
if auth_result['allowed']:
# Proceed with AI call
pass
Legacy Context Manager (Deprecated)
The SDK still supports the legacy context manager pattern:
from agentguard import protect
with protect(context={"user_id": "123"}) as guard:
response = openai.ChatCompletion.create(...)
guard.complete(response)
Configuration
Environment Variables
AGENTGUARD_API_KEY: Your API key (required)AGENTGUARD_TENANT_ID: Default tenant IDAGENTGUARD_PRINCIPAL: Default principal/userAGENTGUARD_BASE_URL: API base URL (defaults to https://api.agentguard.pro)
Initialization Options
agentguard = AgentGuard(
api_key="your-api-key", # Or use env var
tenant_id="your-tenant", # Or use env var
principal="user@example.com", # Or use env var
base_url="https://custom.api" # Or use env var
)
Examples
See the examples/ directory for complete examples:
- intercept_demo.py - Basic intercept() usage
- openai_integration.py - OpenAI integration
- More examples coming soon!
Support
- 📧 Email: support@agentguard.pro
- 📚 Documentation: https://docs.agentguardpro.com
- 💬 Discord: https://discord.gg/agentguard
Release files for agentguard-pro 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| agentguard_pro-0.1.4.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentguard_pro-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.4 kB
Release files / agentguard_pro-0.1.4.tar.gz
| Download URL | agentguard_pro-0.1.4.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b78c7161a9f4d5003060996249da8375b8b2076ff440ee37cb9eae3dbb5aba94
|
|
BLAKE2b-256 checksum How to use checksums |
f28e07cf26e567ac86172637e7849a16610ca803a9bc4ba59c97ba4312ae5b97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / agentguard_pro-0.1.4-py3-none-any.whl
| Download URL | agentguard_pro-0.1.4-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
296236edfc4ee5f55fd2e8695422ed35b955886021f8bd902ce46c8f09008069
|
|
BLAKE2b-256 checksum How to use checksums |
aed7c088400e53890fb8866a702430ac9dd8bba5d3b710972315e21ac12e5eb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|