CrewAI + Tork Governance
Add safety guardrails to your CrewAI multi-agent systems. Govern agent tasks, inter-agent communication, and crew outputs with policy enforcement and audit trails.
Crew Governance
Wrap entire crews with one call
Agent Control
Govern individual agents
Task Validation
Check inputs and outputs
Communication
Monitor inter-agent messages
Installation
Install Tork with CrewAI dependencies.
CrewAI adapters are in tork.adapters.crewai.
TorkCrewAIMiddleware
The main entry point for CrewAI governance.
The middleware provides methods to wrap agents and crews, and handles governance checks before and after task execution automatically.
Middleware Methods
| wrap_agent() | Wrap a single agent with governance |
| wrap_crew() | Wrap an entire crew (all agents) |
| before_task() | Called before task execution |
| after_task() | Called after task completion |
GovernedAgent
Wrap individual CrewAI agents with governance controls.
GovernedAgent wraps a single agent to validate task inputs before execution and check outputs after. Use when you need granular control over specific agents.
GovernedCrew
Wrap entire CrewAI crews for comprehensive governance.
GovernedCrew automatically wraps all agents in a crew. This is the easiest way to add governance to existing multi-agent workflows.
TorkGovernedTask
Apply governance to individual tasks.
For fine-grained control, wrap individual tasks to validate their descriptions and outputs against policies.
Complete Workflow Example
A production-ready customer service crew with full governance.
Inter-Agent Communication
Governance for agent delegation and collaboration.
When agents delegate tasks to each other, governance is automatically applied to the delegation request and response. This ensures that even internal agent communication follows your policies.
Error Handling
Handle governance violations gracefully.
The adapter raises specific exceptions for different violation types. Catch these to provide appropriate user feedback.
Exception Types
| GovernanceBlockedError | Content blocked by policy (toxicity, jailbreak, etc.) |
| PIIDetectedError | Personal information detected and blocked |
Advanced Topics
Compliance receipts and configuration
Best Practices
Use GovernedCrew for simplicity
Wrapping the entire crew is easier and ensures all agents are governed consistently.
Handle exceptions gracefully
Catch GovernanceBlockedError and PIIDetectedError to provide user-friendly responses.
Set meaningful agent IDs
Use descriptive agent_id values to identify which crew/agent triggered violations in logs.
Enable receipts for compliance
The middleware automatically generates compliance receipts for audit trails.
Test with strict policies first
Start with stricter policies and relax as needed to find the right balance.
Imports Reference
Next Steps
Configure policies in the dashboard or explore other framework integrations.