Python SDK for AgentGuard - AI Agent governance and monitoring platform
Project description
AgentGuard Python SDK
Python SDK for integrating with AgentGuard - AI Agent governance and monitoring platform.
Features
- ✅ Zero Code Changes - Drop-in replacement for OpenAI client
- ✅ Transparent Proxy - All requests routed through AgentGuard
- ✅ Webhook Support - Real-time approval notifications
- ✅ Business API Interception - Monitor all API calls
- ✅ Cost Tracking - Automatic cost monitoring
- ✅ Policy Enforcement - Apply governance policies
- ✅ Approval Workflows - Handle high-risk operations
Installation
pip install agentguard-zhx
Quick Start
Basic Usage
from agentguard import AgentGuardOpenAI
# Initialize client
client = AgentGuardOpenAI(
agentguard_url="http://localhost:8080",
agent_api_key="ag_xxx"
)
# Use standard OpenAI API
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
Environment Variables
# Set environment variables
export AGENTGUARD_URL="http://localhost:8080"
export AGENTGUARD_API_KEY="ag_xxx"
# Use without explicit configuration
from agentguard import AgentGuardOpenAI
client = AgentGuardOpenAI() # Loads from environment
Webhook Approval
import threading
from agentguard import AgentGuardOpenAI, WebhookServer
# Start webhook server
webhook_server = WebhookServer(port=5000, secret="your-secret")
webhook_thread = threading.Thread(target=webhook_server.start, daemon=True)
webhook_thread.start()
# Use client as normal
client = AgentGuardOpenAI(
agentguard_url="http://localhost:8080",
agent_api_key="ag_xxx"
)
# Approvals are handled automatically via webhooks
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "High-risk operation"}]
)
Business API Interception
from agentguard import enable_agentguard
import requests
# Enable global interception
enable_agentguard(
agentguard_url="http://localhost:8080",
agent_api_key="ag_xxx",
intercept_patterns=[r"https://api\.example\.com/.*"]
)
# All matching requests go through AgentGuard
response = requests.get("https://api.example.com/data")
Configuration
AgentGuardConfig
from agentguard import AgentGuardConfig, AgentGuardOpenAI
config = AgentGuardConfig(
agentguard_url="http://localhost:8080",
agent_api_key="ag_xxx",
webhook_url="http://your-server.com/webhook",
webhook_secret="your-secret"
)
client = AgentGuardOpenAI(config=config)
WebhookServer Options
from agentguard import WebhookServer
server = WebhookServer(
port=5000, # Port to listen on
secret="your-secret", # HMAC signature secret
host="0.0.0.0" # Host to bind to
)
Examples
See the examples/ directory for more examples:
basic_usage.py- Basic OpenAI integrationwebhook_approval.py- Webhook-based approval handlingbusiness_api.py- Business API interception
API Reference
AgentGuardOpenAI
Drop-in replacement for OpenAI client that routes requests through AgentGuard.
Parameters:
agentguard_url(str): AgentGuard server URLagent_api_key(str): AgentGuard API keyconfig(AgentGuardConfig, optional): Configuration object
WebhookServer
Lightweight webhook server for receiving approval notifications.
Methods:
start()- Start the server (blocking)register_callback(approval_id, callback)- Register approval callbackwait_for_approval(approval_id, timeout)- Wait for approval with timeout
enable_agentguard()
Enable global request interception for the requests library.
Parameters:
agentguard_url(str): AgentGuard server URLagent_api_key(str): AgentGuard API keyintercept_patterns(List[str], optional): URL patterns to intercept (regex)
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black agentguard/
# Lint code
ruff check agentguard/
License
MIT License
Support
- Documentation: https://docs.agentguard.io
- Issues: https://github.com/agentguard/agentguard-sdk-python/issues
- Email: support@agentguard.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentguard_zhx-0.0.1.tar.gz.
File metadata
- Download URL: agentguard_zhx-0.0.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b81b0c487505078a340ce12c5924f7271e3372db50c3b25a8905f8ec8ffb7fe
|
|
| MD5 |
774b82d729cd4d84e19084e1768a1c3e
|
|
| BLAKE2b-256 |
62b0cfb05670602fb6f91bf33c5c6c72f0a200f1d842f64c55997c10aa24607e
|
File details
Details for the file agentguard_zhx-0.0.1-py3-none-any.whl.
File metadata
- Download URL: agentguard_zhx-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fda5ba02199b7715415934bda267ff426cbbbba95235ed94402b0a89ddc94dce
|
|
| MD5 |
bfe3f7a37d2e51af9688703c81954181
|
|
| BLAKE2b-256 |
92470bfc231f41927179d7027b45b07dc0934e0b0bfbcc113ad80fe4ede423cc
|