Python SDK

Official Python client library for AGEI integration

Installation

Download SDK

Download the SDK from the repository:

# Download ciaf_client_v2.py from repository
wget https://your-repo/examples/ciaf_client_v2.py

# Or copy from examples/ directory
cp examples/ciaf_client_v2.py ./

Dependencies

pip install requests python-dotenv

Quick Start

Initialize and use the AGEI client

from ciaf_client_v2 import AGEIClient
import os

# Initialize client
client = AGEIClient(
    base_url=os.getenv("CIAF_BASE_URL"),
    api_key=os.getenv("SUPABASE_SERVICE_ROLE_KEY")
)

# Test connection
client.health_check()
print("✓ Connected to AGEI")

Client Methods

Policy Gate Evaluation

# Evaluate evidence against policy gate
result = client.evaluate_gate(
    organization_id="org-uuid",
    gate_definition_id="gate-uuid",
    policy_version_id="policy-uuid",
    evidence_payload={
        "accuracy": 0.97,
        "bias_score": 0.05,
        "model_name": "credit-risk-v2"
    }
)

print(f"Outcome: {result['evaluation']['outcome']}")
print(f"Reason: {result['evaluation']['reasonCode']}")
print(f"Receipt Hash: {result['receipt']['hash']}")

Agent Session Management

# Start agent session
session = client.start_agent_session(
    organization_id="org-uuid",
    session_key="session-20260503-001",
    agent_principal_id="agent-uuid",
    workflow_name="customer_support",
    session_context={
        "customer_id": "cust-123",
        "issue_type": "billing"
    }
)

print(f"Session ID: {session['session']['id']}")
print(f"Receipt: {session['receipt']['hash']}")

Agent Tool Evaluation

# Evaluate tool request (with auto-HITL for critical tools)
result = client.evaluate_tool_request(
    organization_id="org-uuid",
    agent_session_id="session-uuid",
    tool_definition_id="tool-uuid",
    policy_version_id="policy-uuid",
    tool_key="send_customer_message",
    tool_params={
        "message": "Your bill is ready",
        "customer_id": "cust-123"
    },
    agent_principal_id="agent-uuid"
)

# Check if escalated to HITL
if 'hitl' in result:
    print(f"Escalated to HITL: {result['hitl']['requestNumber']}")
    print(f"Approval Link: {result['hitl']['approvalLink']}")
else:
    print(f"Outcome: {result['gateEvaluation']['outcome']}")

HITL Request Creation

# Create HITL review request
hitl = client.create_hitl_request(
    organization_id="org-uuid",
    request_type="model_deployment",
    resource_type="ai_model",
    resource_id="model-123",
    risk_classification="high",
    required_reviewer_role="model_risk_reviewer",
    policy_reason_code="HIGH_RISK_MODEL_DEPLOYMENT",
    evidence_summary={
        "model_name": "credit-risk-v2",
        "accuracy": 0.94
    }
)

print(f"Request Number: {hitl['requestNumber']}")
print(f"Expires At: {hitl['expiresAt']}")
print(f"Approval Link: {hitl['approvalLink']}")

Agent Security Monitoring

# List anomaly alerts
alerts = client.list_anomaly_alerts(
    organization_id="org-uuid",
    status="open",
    severity="critical"
)

for alert in alerts['alerts']:
    print(f"{alert['anomaly_type']}: {alert['description']}")
    print(f"  Severity: {alert['severity']}")
    print(f"  Deviation: {alert['deviation_score']}σ")
    
# Create behavior baseline
baseline = client.create_behavior_baseline(
    organization_id="org-uuid",
    agent_principal_id="agent-uuid",
    typical_tools_used=["lookup_customer", "send_email"],
    typical_request_volume_per_hour=45,
    max_requests_per_minute=100
)

print(f"Baseline created: {baseline['baseline']['id']}")

Error Handling

Retry logic and exponential backoff included

try:
    result = client.evaluate_gate(...)
except requests.exceptions.HTTPError as e:
    if e.response.status_code == 400:
        print("Bad request:", e.response.json())
    elif e.response.status_code == 401:
        print("Unauthorized: Check API key")
    elif e.response.status_code == 429:
        print("Rate limit exceeded")
    else:
        print(f"Error {e.response.status_code}: {e.response.text}")
except Exception as e:
    print(f"Unexpected error: {e}")

SDK Features

Automatic Retry

Exponential backoff for failed requests

Type Hints

Full type annotations for IDE support

Environment Config

Load credentials from .env files

Comprehensive Methods

Cover all AGEI API endpoints

Example Scripts

Complete demos in examples/ directory

agei_end_to_end_demo.py
Complete Workflow
agent_behavior_monitoring_demo.py
Security Monitoring
hitl_demo.py
Human Review
policy_gate_demo.py
Gate Evaluation