Skip to main content
This example demonstrates how to integrate the agent-control SDK into an existing application. It simulates a Customer Support Agent, a realistic enterprise scenario that shows the key patterns for protecting AI agents with server-defined controls.

Why This Example?

  • Universally understood use case: customer support is familiar to everyone
  • Natural need for guardrails: PII protection, prompt injection defense
  • Multiple operation types: LLM calls and tool calls (database, knowledge base, tickets)
  • Enterprise-relevant: shows patterns real companies would use

Quick Start

The demo.sh start command:
  • Starts PostgreSQL database
  • Runs migrations
  • Starts the API server (http://localhost:8000)
  • Starts the UI (http://localhost:4000)
  • Registers the agent with demo controls (PII detection, prompt injection)
When you open the UI, you will see the agent with controls already configured.

Other Commands

Prerequisites

First-Time Setup

  1. Install the SDK and evaluators:
  2. Install UI dependencies:

Manual Setup (alternative to demo.sh)

If you prefer to run services manually:
  1. Start the database (requires Docker):
  2. Run database migrations:
  3. Start the server (Terminal 1):
    Server runs at http://localhost:8000
  4. Start the UI (Terminal 2):
    UI runs at http://localhost:4000

Running the Demo

After demo.sh start, the agent already has demo controls configured. Run:
Test different scenarios:

Automated Mode

Reset Agent Controls

Adding Custom Controls

  1. Open http://localhost:4000
  2. Click on “Customer Support Agent” in the list
  3. Click “Add Control” to create additional controls
See Example Controls below for configuration examples.

Available Commands

Key Concepts

1. SDK Initialization

Initialize once at application startup:
This:
  • Registers the agent with the server
  • Fetches controls associated with the agent
  • Enables the @control() decorator

2. Protecting Functions

Use the @control() decorator on any function you want to protect:
The decorator:
  • Calls the server with check_stage="pre" before execution (validates input)
  • Calls the server with check_stage="post" after execution (validates output)
  • Raises ControlViolationError if a control triggers with “deny” action

3. Handling Violations

Catch ControlViolationError to provide graceful fallbacks:

4. Controls are Server-Side

Controls are defined on the server via the UI, not in code. This design provides:
  • Centralized management: security team controls safeguards without code changes
  • Instant updates: change controls without redeploying agents
  • Audit trail: server logs all control evaluations
  • Separation of concerns: developers focus on features, security team on safeguards

Project Structure

demo.sh

Manages the full demo lifecycle:
  • start - Starts database, server, UI, and sets up demo controls
  • stop - Stops all services
  • reset - Deletes database and stops services
  • status - Shows service status

setup_demo_controls.py

Creates the demo agent with pre-configured controls:
  • block-ssn-in-output - Blocks responses containing SSN patterns
  • block-prompt-injection - Blocks common injection attempts
  • block-credit-card - Blocks credit card numbers in input

support_agent.py

Contains:
  • SDK initialization
  • Mock services (LLM, database, knowledge base, tickets)
  • Protected functions with @control() decorator
  • CustomerSupportAgent class with error handling

run_demo.py

Contains:
  • Interactive chat loop
  • Test command handlers (/test-pii, /test-injection, etc.)
  • Automated test scenarios

Example Controls to Configure

The demo setup creates three controls automatically. Here are examples of additional controls you might add:

PII Detection (Post-check on output)

Prompt Injection (Pre-check on input)

Toxic Content (Pre-check on input)

Testing the Integration

  1. Without controls: Run the demo without configuring any controls. All messages should pass through.
  2. With PII control: Add a PII detection control, then run /test-pii. Messages with SSN patterns should be blocked.
  3. With injection control: Add a prompt injection control, then run /test-injection. Injection attempts should be blocked.

Next Steps

  • Explore the main examples for more integration patterns
  • Read the SDK documentation

Source Code

View the complete example with all scripts and setup instructions: Customer Support Agent Example