Catalog PyPI
PACKAGE EXPLORERView in registry

agentguard-pro

PyPI

Python SDK for AgentGuard Pro - AI governance and compliance platform

agentguardaiauthorizationcomplianceenterprisegovernancesecurity
Versions collected1
Direct dependencies7From release 0.1.4
Last observed20 Oct, 22:06 UTC

README

Version 0.1.4 documentation

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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.412 Jun 20257

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:06 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:74d9cd34af3a72ed8f7355ad5866284bcba4ef08e435b00bfad2d04f46f5b385