Skip to main content

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
  • 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 integration
  • approval_polling.py - Query approval status
  • business_api.py - Business API interception

API Reference

AgentGuardOpenAI

Drop-in replacement for OpenAI client with integrated approval management.

Parameters:

  • agentguard_url (str): AgentGuard server URL
  • agent_api_key (str): AgentGuard API key
  • config (AgentGuardConfig, optional): Configuration object

Integrated Approval Management:

Access via client.approvals:

  • get_status(approval_id) - Query approval status by ID
  • submit_reason(approval_id, reason) - Submit approval reason/justification

Returns: ApprovalStatusResponse with:

  • status - ApprovalStatus enum (PENDING/APPROVED/REJECTED/EXPIRED)
  • execution_result - Result if approved and executed
  • remark - Rejection reason if rejected
  • is_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 URL
  • agent_api_key (str): AgentGuard API key
  • intercept_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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentguard_zhx-0.0.2.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentguard_zhx-0.0.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file agentguard_zhx-0.0.2.tar.gz.

File metadata

  • Download URL: agentguard_zhx-0.0.2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agentguard_zhx-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2bceb6ff26336bf452291192b3fb2dfaa01c504d49f1607453dae0a21388937c
MD5 a4fe2df0f533e1309c3580fa67b2499e
BLAKE2b-256 d5ce7cb211f3b42a5b18b80281ac61c928675fdbc76a2197120326dd9a09bff8

See more details on using hashes here.

File details

Details for the file agentguard_zhx-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: agentguard_zhx-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agentguard_zhx-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bceb014faa6e25c058988e0484f47b879fbfbe0522c9fe41138899d721cb5650
MD5 05b307b5780396ec6f3e80a956528ee7
BLAKE2b-256 3e828ad7607a31ebe45fe3c6d84e678cac581a7de5b980b35f4a836748001298

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page