Skip to main content

Python SDK for AgentGuard Pro - AI governance and compliance platform

Project description

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 ID
  • AGENTGUARD_PRINCIPAL: Default principal/user
  • AGENTGUARD_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:

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_pro-0.1.4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

agentguard_pro-0.1.4-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file agentguard_pro-0.1.4.tar.gz.

File metadata

  • Download URL: agentguard_pro-0.1.4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for agentguard_pro-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b78c7161a9f4d5003060996249da8375b8b2076ff440ee37cb9eae3dbb5aba94
MD5 ae873dd1ad674596110f9dabaad5c0bd
BLAKE2b-256 f28e07cf26e567ac86172637e7849a16610ca803a9bc4ba59c97ba4312ae5b97

See more details on using hashes here.

File details

Details for the file agentguard_pro-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: agentguard_pro-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for agentguard_pro-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 296236edfc4ee5f55fd2e8695422ed35b955886021f8bd902ce46c8f09008069
MD5 4d5a4d3b5d280c4d9787d0fc7e90ca02
BLAKE2b-256 aed7c088400e53890fb8866a702430ac9dd8bba5d3b710972315e21ac12e5eb5

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