The source code for this example is available on GitHub:
Customer Support Agent
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 + tool calls (database, knowledge base, tickets)
- Enterprise-relevant: Shows patterns real companies would use
Quick Start
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)
Other Commands
Prerequisites
First-Time Setup
-
Install the SDK and evaluators:
-
Install UI dependencies:
Manual Setup (alternative to demo.sh)
If you prefer to run services manually:Start the server (Terminal 1)
Start the UI (Terminal 2)
Running the Demo
Afterdemo.sh start, the agent already has demo controls configured. Just run:
Automated Mode
Run all test scenarios automatically:Reset Agent Controls
To remove all controls from the agent (keeps the agent registered):Adding Custom Controls
- Open http://localhost:4000
- Click on “Customer Support Agent” in the list
- Click “Add Control” to create additional controls
Available Commands
| Command | Description |
|---|---|
/help | Show all commands |
/test-safe | Run safe message tests |
/test-pii | Test PII detection (if control configured) |
/test-injection | Test prompt injection detection |
/lookup <query> | Look up customer (e.g., /lookup C001) |
/search <query> | Search knowledge base |
/ticket | Create a test support ticket |
/quit | Exit the demo |
Key Concepts
1. SDK Initialization
Initialize once at application startup:- Registers the agent with the server
- Fetches the assigned policy and controls
- Enables the
@control()decorator
2. Protecting Functions
Use the@control() decorator on any function you want to protect:
- Calls the server with
check_stage="pre"before execution (validates input) - Calls the server with
check_stage="post"after execution (validates output) - Raises
ControlViolationErrorif a control triggers with “deny” action
3. Handling Violations
CatchControlViolationError to provide graceful fallbacks:
4. Controls are Server-Side
Important: Controls are defined on the server via the UI, not in code. This design provides:- Centralized management: Security team controls policies 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 policies
Project Structure
demo.sh
Manages the full demo lifecycle:start- Starts database, server, UI, and sets up demo controlsstop- Stops all servicesreset- Deletes database and stops servicesstatus- Shows service status
setup_demo_controls.py
Creates the demo agent with pre-configured controls:block-ssn-in-output- Blocks responses containing SSN patternsblock-prompt-injection- Blocks common injection attemptsblock-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 CustomerSupportAgentclass 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
- Without controls: Run the demo without configuring any controls. All messages should pass through.
-
With PII control: Add a PII detection control, then run
/test-pii. Messages with SSN patterns should be blocked. -
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
Overview
This example demonstrates a customer support agent protected by Agent Control with multiple controls:- PII blocking — Prevents SSN and credit card numbers in responses
- Toxicity detection — Blocks toxic or harmful user messages via Luna-2
- Tool restriction — Limits which tools the agent can invoke