Overview
This example demonstrates integrating Agent Control with CrewAI to provide multi-layer security for a customer support agent:- Agent Control for security/compliance — PII detection, unauthorized access blocking
- CrewAI Guardrails for quality validation — length, tone, structure
To run the full example yourself, visit the source on GitHub:
CrewAI Example
Why This Matters
Customer support agents (human or AI) can accidentally:- Leak PII (emails, phones, SSNs, credit cards) in responses or logs
- Access other users’ data when they shouldn’t
- Disclose passwords, credentials, or admin information
- Violate GDPR, CCPA, PCI-DSS compliance requirements
Prerequisites
1. Start the Agent Control Server
Expected Behavior
Scenario 2: PII Leakage — POST blocks output
Scenario 2: PII Leakage — POST blocks output
Scenario 2.5: Quality Issues — CrewAI Guardrails retry
Scenario 2.5: Quality Issues — CrewAI Guardrails retry
Scenario 3: Orchestration Bypass — Final output validation
Scenario 3: Orchestration Bypass — Final output validation
Agent Control vs CrewAI Guardrails
How It Works
The @control() decorator with CrewAI tools
CrewAI tools are synchronous, but the @control() decorator is async. Use an asyncio.run() wrapper:
Three-layer validation flow
Why three layers?- Layers 1 & 2 protect at the tool boundary (standard
@control()usage) - Layer 3 protects against orchestration bypass — when CrewAI’s agent generates its own response containing PII after a tool was blocked
Control configuration
Architecture
Files
Troubleshooting
"event loop already running" error
"event loop already running" error
CrewAI tools are sync by default, but
@control requires async. Use an asyncio.run() wrapper:Control not triggering
Control not triggering
Most common cause: the setup script was not run.Also verify the tool name is set on the async function:
"Arguments validation failed" error
"Arguments validation failed" error
CrewAI may pass tool arguments in different formats. Make the tool handle both: