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
- ✅ Unified Client - One client for all features (LLM + Approvals)
- ✅ Transparent Proxy - All requests routed through AgentGuard
- ✅ Integrated Approval Management - Built-in approval status query and submission
- ✅ 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)
Approval Status Query
Query approval status using integrated approval management:
from agentguard import AgentGuardOpenAI
# One client for everything
client = AgentGuardOpenAI(
agentguard_url="http://localhost:8080",
agent_api_key="ag_xxx"
)
# LLM calls
response = client.chat.completions.create(...)
# Approval management (integrated)
status = client.approvals.get_status("approval_id")
if status.is_approved:
print("Approved:", status.execution_result)
elif status.is_rejected:
print("Rejected:", status.remark)
# Submit approval reason
client.approvals.submit_reason("approval_id", "Need to delete test data")
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
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"
)
client = AgentGuardOpenAI(config=config)
Examples
See the examples/ directory for more examples:
basic_usage.py- Basic OpenAI integrationapproval_polling.py- Query approval statusbusiness_api.py- Business API interception
API Reference
AgentGuardOpenAI
Drop-in replacement for OpenAI client with integrated approval management.
Parameters:
agentguard_url(str): AgentGuard server URLagent_api_key(str): AgentGuard API keyconfig(AgentGuardConfig, optional): Configuration object
Integrated Approval Management:
Access via client.approvals:
get_status(approval_id)- Query approval status by IDsubmit_reason(approval_id, reason)- Submit approval reason/justification
Returns: ApprovalStatusResponse with:
status- ApprovalStatus enum (PENDING/APPROVED/REJECTED/EXPIRED)execution_result- Result if approved and executedremark- Rejection reason if rejectedis_pending,is_approved,is_rejected,is_expired- Helper properties
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
Release files for agentguard-zhx 0.0.3
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_zhx-0.0.3.tar.gz | 14.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentguard_zhx-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.3 kB
Release files / agentguard_zhx-0.0.3.tar.gz
| Download URL | agentguard_zhx-0.0.3.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1456a6071e7b45d7c7767e57a37f7c120e30e36091569286020c61b0351643c9
|
|
BLAKE2b-256 checksum How to use checksums |
7a9f23995a9f4ba59bf38079a43f8a27f7c18e8e3c0c3b3f92a202b06aeb20ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|
Release files / agentguard_zhx-0.0.3-py3-none-any.whl
| Download URL | agentguard_zhx-0.0.3-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c9f1e8bd1c874ec974de45c99c46d0d5b67f57ee332f7b14028c0e4cb0d855e
|
|
BLAKE2b-256 checksum How to use checksums |
012bbfa51d523399c1635cf8cd6fa570a2a089d98cc4cc2044130606a8608710
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|