Overview
This demo shows how to:- Create an agent and register it with the Agent Control server
- Define controls (regex, list-based) and associate them with the agent
- Run an agent that uses the
@controldecorator with server-side controls - Dynamically update controls on the server (enable or disable rules without redeploying code)
Prerequisites
Before running this example:-
Start the Agent Control server from the monorepo root:
-
Verify the server is running:
-
Install dependencies (if not already done from monorepo root):
Quick Start
Step 1: Create Controls on the Server
Run the setup script to create the agent and controls:- A demo agent (
demo-chatbot) - Two controls:
- block-SSN-output: Regex control to detect and block Social Security Numbers
- block-banned-words: List-based control to block profanity and sensitive keywords
- A policy with both controls assigned to the agent
Step 2: Run the Demo Agent
Start the agent that uses server-side controls:- Initialize with
agent_control.init()to connect to the server - Load the assigned controls
- Apply the
@control()decorator to protect functions - Test various scenarios:
- Normal message (allowed)
- Message containing banned words (blocked)
- Message with allowed content (passes)
- Tool output containing SSN (blocked)
Step 3: Update Controls Dynamically
Update controls on the server without changing code or restarting the agent:Files
| File | Description |
|---|---|
setup_controls.py | Creates agent, controls, and assigns controls to the agent |
demo_agent.py | Demo agent using @control decorator with server-side policies |
update_controls.py | Updates controls dynamically (enable or disable SSN blocking) |
How It Works
1. Server-Side Control Definition
Controls are defined on the server with:- Scope: When to check (step types, stages: pre or post)
- Condition: What and how to check
- Action: What to do (allow, deny, steer, warn, log)
setup_controls.py:
2. Agent Integration
The agent uses the@control() decorator which:
- Automatically fetches assigned controls from server
- Evaluates controls before or after function execution
- Blocks violations or allows safe operations
demo_agent.py:
3. Dynamic Updates
Controls can be updated on the server without code changes:- Enable or disable controls
- Update patterns and rules
- Change enforcement decisions (deny to warn)
- Add new controls to existing agents
Configuration
All scripts use the same agent configuration:AGENT_CONTROL_URL to connect to a different server:
Source Code
View the complete example with all scripts and setup instructions:Agent Control Demo Example
Troubleshooting
Server Connection Issues
Error:Failed to connect to server
Fix:
Agent Not Found
Error:Agent not found when running demo_agent.py
Fix: Run setup_controls.py first:
Import Errors
Error:ModuleNotFoundError: No module named 'agent_control'
Fix: Install dependencies from monorepo root: