Code Examples

Working demos and integration patterns for AGEI

Running Examples

1. Configure Environment

export CIAF_BASE_URL="http://localhost:3001"
export TEST_ORG_ID="your-org-id"
export AGENT_PRINCIPAL_ID="your-agent-id"
export SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"

2. Run Example

cd examples
python agei_end_to_end_demo.py

agei_end_to_end_demo.py

Complete governance workflow demonstration

Recommended

Demonstrates complete AGEI workflow from agent session to HITL review to anomaly detection. Shows all major features in one 5-minute demo.

What it shows:

  • • Starting an agent session
  • • Registering agent tools with risk classification
  • • Tool evaluation with automatic HITL escalation
  • • Creating behavior baselines
  • • Detecting anomalies and automated responses
  • • Complete cryptographic evidence trail

agent_behavior_monitoring_demo.py

Agent anomaly detection system

Demonstrates behavioral baseline creation and 6 types of anomaly detection with automated security responses.

Simulated Scenarios:

  • • Unusual tool usage (tool not in baseline)
  • • Request volume spike (8.5σ deviation)
  • • Off-hours access (Sunday 2:30 AM)
  • • Failed authentication attempts
  • • Privilege escalation attempt
  • • Automated responses (session terminated, API key suspended)

policy_gate_demo.py

Policy gate evaluation patterns

Shows four-outcome gate model with specific reason codes and server-side policy evaluation.

Outcomes Demonstrated:

  • Approve - Evidence satisfies policy (accuracy ≥ threshold)
  • Deny - Clear policy violation (bias exceeds limit)
  • Escalate - Critical risk requires human review
  • Inspect - Missing required evidence fields

hitl_demo.py

Human-in-the-loop review workflow

Complete HITL workflow from escalation creation to reviewer notification to decision recording.

Workflow Steps:

  • • Create HITL request with evidence package
  • • Generate SHA-256 approval token
  • • Send SendGrid notification to reviewer
  • • Display approval link and expiration time
  • • Show SLA-based timeout (15min - 4hr)
  • • Demonstrate decision types (approve/deny/modify)

agent_tools_demo.py

Agent tool registration and evaluation

Shows how to register agent tools with risk classifications and evaluate tool requests with automatic HITL escalation for critical tools.

Tool Risk Classes:

  • Low - Read-only operations (lookup_customer)
  • Moderate - Standard actions (create_ticket)
  • High - Sensitive operations (send_customer_message)
  • Critical - Requires human review (delete_customer_data)

receipt_verification_demo.py

Cryptographic evidence verification

Demonstrates how to verify cryptographic receipts, check hash chains, and validate evidence integrity.

Verification Steps:

  • • Retrieve receipt from database
  • • Verify SHA-256 content hash
  • • Check optional digital signature
  • • Validate hash chain to parent evidence
  • • Verify Merkle proof (if applicable)

audit_pack_export_demo.py

Compliance evidence export

Shows how to create audit packs for regulatory compliance, including all receipts, evaluations, and decisions for a specific model or workflow.

Export Includes:

  • • All receipts for specific model/agent
  • • Policy evaluations with outcomes
  • • HITL requests and decisions
  • • Anomaly alerts and responses
  • • Cryptographic sealing for immutability

SQL Examples

demo_lifecycle.sql

Complete AI lifecycle demonstration

Creates sample organization, policies, gates, and complete evidence trail from dataset ingestion through model deployment to inference.

-- Run in Supabase SQL Editor
\i supabase/demo_lifecycle.sql