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
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 database (requires Docker):
-
Run database migrations:
-
Start the server (Terminal 1):
Server runs at
http://localhost:8000 -
Start the UI (Terminal 2):
UI runs at
http://localhost:4000
Running the Demo
Afterdemo.sh start, the agent already has demo controls configured. Run:
Automated Mode
Reset Agent Controls
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 (for example, /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 controls associated with the agent
- 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
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 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
Source Code
View the complete example with all scripts and setup instructions:Customer Support Agent Example