Skip to main content
Complete example demonstrating the Agent Control workflow: creating controls, running a controlled agent, and dynamically updating controls without code changes.

Overview

This demo shows how to:
  1. Create an agent and register it with the Agent Control server
  2. Define controls (regex, list-based) and associate them with the agent
  3. Run an agent that uses the @control decorator with server-side controls
  4. Dynamically update controls on the server (enable or disable rules without redeploying code)

Prerequisites

Before running this example:
  1. Start the Agent Control server from the monorepo root:
  2. Verify the server is running:
  3. 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:
This creates:
  • 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:
The agent will:
  • 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:
Key insight: controls are enforced server-side, so you can update rules in real time without redeploying code.

Files

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 (deny, steer, observe)
Example from 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
Example from 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 observe)
  • Add new controls to existing agents

Configuration

All scripts use the same agent configuration:
Set 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: