Overview
Agent Sentinel provides native integrations with popular agent frameworks, enabling automatic tracking of:
- Agent actions and tool calls
- LLM invocations
- Chain execution
- Token usage and costs
- Errors and retries
The “Big Three” frameworks are supported:
- LangChain: Callback-based integration
- CrewAI: Wrapper-based integration
- AutoGen: Hook-based integration (NEW!)
AutoGen integration
SentinelInspector
Microsoft’s AutoGen is the leading framework in enterprise environments. Agent Sentinel provides seamless integration using AutoGen’s built-in register_reply hook system.
How it works
AutoGen’s architecture is different from LangChain/CrewAI:
- Agents communicate via messages: Agents send messages back and forth
- Reply chain system: AutoGen uses
register_reply() to inject hooks
- LLM config: LLMs are configured through
llm_config dict
Sentinel leverages this by:
- Hooking the reply chain (position 0 = highest priority)
- Wrapping LLM generation to track token costs
- Monitoring message flow for audit trail
This is simpler than CrewAI because AutoGen has a built-in hook system designed exactly for this purpose!
What’s tracked
The inspector automatically tracks:
-
Agent-to-agent messages:
- Sender and recipient
- Message content (preview)
- Message count per agent
- Timestamp and sequence
-
LLM calls:
- Model name
- Token usage (prompt + completion)
- Calculated cost
- Duration
-
Policy enforcement:
- Authorization checks before replies
- Budget validation
- Rate limiting
- Intervention recording
Run lifecycle
Mark run boundaries for accurate tracking:
Run summary
Get detailed statistics after execution:
Policy enforcement
Sentinel blocks agents that violate policies:
When blocked, Sentinel:
- Returns a blocking message to the agent
- Records an intervention for dashboard visibility
- Prevents the agent from generating a reply
- Raises
BudgetExceededError to stop execution
Convenience function
Create and secure agents in one step:
LangChain integration
SentinelCallbackHandler
Use Agent Sentinel’s callback handler to track all LangChain activity:
What’s tracked
The callback handler automatically tracks:
1. LLM calls:
- Model name (normalized to pricing database)
- Prompt tokens
- Completion tokens
- Total tokens
- Calculated cost (using latest pricing data)
- Duration
- Run ID and parent run ID (for nested chains)
2. Tool/function calls:
- Tool name
- Input arguments (first 200 chars)
- Output/result (first 200 chars)
- Duration
- Success/failure status
- Error details (if failed)
3. Agent actions:
- Tool selection
- Agent reasoning
- Observations
- Action outcomes
4. Chain execution:
- Chain type/name
- Chain start/end
- Duration
- Nested chain relationships (parent/child)
- Error handling
5. Policy enforcement (when enforce_policies=True):
- Authorization checks before LLM calls
- Authorization checks before tool execution
- Budget validation
- Intervention recording when actions are blocked
Policy enforcement
Sentinel actively blocks operations that violate policies:
When blocked:
on_llm_start() runs authorization check
PolicyEngine.check_action() validates budget
- If violation,
BudgetExceededError is raised
- Intervention is recorded (type, reason, cost, inputs)
- LLM call never reaches the API
- Exception propagates to your code
The same authorization happens for tools via on_tool_start().
Run summary
Get a complete summary after execution:
Async LangChain
The callback handler supports async chains:
LangGraph integration
SentinelToolNode wraps a LangGraph tool node so every tool invocation runs through the Sentinel policy engine — including evidence requirements, grounding rules, and structured self-repair feedback when a call is rejected.
Each entry maps a tool name to (callable, guard_kwargs) where guard_kwargs accepts the same metadata as @guarded_action (is_commit, requires, grounding_rules, produces_evidence, risk_level, etc.).
Self-repair on block
When the policy engine rejects a tool call, SentinelToolNode returns a ToolMessage whose content is a structured remediation payload the LLM can read on the next turn:
Most frontier models will read the retry_guidance and self-correct without any prompt-engineering on your side.
Working example
A complete runnable example lives at examples/langgraph_sentinel.py in the public SDK repo — a 3-tool refund workflow that demonstrates evidence requirements, grounding constraints, and self-repair when the agent attempts a commit before the prerequisite lookup.
CrewAI integration
SentinelCrew wrapper
SentinelCrew provides automatic security injection for CrewAI - transforming it from passive tracking to active “Visa-like” control:
What’s automatically secured
SentinelCrew injects security at three levels:
1. Tool Injection (The “Chip Reader”)
- Wraps ALL agent tools automatically
- No manual decoration required
- Works with SerperDevTool, DuckDuckGoSearch, FileReadTool, etc.
- Authorization checks run BEFORE tool execution
- Failed authorization blocks the tool and records intervention
2. LLM Monitoring (The “LLM Meter”)
- Attaches
SentinelCallbackHandler to all agent LLMs
- Tracks token costs in real-time
- Enforces budget limits before expensive API calls
- Works with OpenAI, Anthropic, and other LangChain-compatible LLMs
3. Step Monitoring (The “Safety Net”)
- Tracks agent step counts
- Detects runaway agents (infinite loops)
- Enforces
max_agent_steps limit
- Identifies repetition patterns
- Records interventions when agents are stopped
Run summary
Get comprehensive execution statistics:
Policy enforcement example
Prevent runaway costs with active blocking:
When a tool or LLM is blocked:
- Authorization fails before execution
- Intervention is recorded (type, reason, risk level)
BudgetExceededError or PolicyViolationError is raised
- Agent execution stops cleanly
- Visible in Console → Interventions page
Runaway agent protection
Prevent infinite loops and excessive iterations:
Loop detection: If an agent repeats the same action 5+ times in a row, a warning is logged and an intervention is recorded.
Step limit: If an agent exceeds max_agent_steps, a critical intervention is recorded and execution is blocked.
Wrapping existing crews
Retrofit existing CrewAI crews without rewriting code:
Individual action wrapping
For fine-grained control, wrap individual actions:
The @wrap_crew_action decorator is a thin wrapper around @guarded_action that adds CrewAI-specific tags and metadata.
Custom framework integration
For frameworks not yet supported, use the low-level @guarded_action decorator:
Combining integrations
Use multiple integrations together:
Best practices
Use framework integrations when available: Framework-specific integrations provide better structure and context than raw @guarded_action decorators.
Set agent_id and run_id: Always provide identifiers for filtering and analysis in the web console.
Review run summaries: Use get_run_summary() to understand cost breakdown and identify expensive operations.
Framework compatibility: Test integrations when upgrading LangChain or CrewAI versions, as internal APIs may change.
Troubleshooting
”LangChain events not tracked”
Ensure callbacks are passed at all levels:
“CrewAI costs not accurate”
CrewAI cost tracking depends on:
- LLM instrumentation (e.g.,
instrument_openai())
- Tool cost annotations via
@wrap_crew_action
Ensure both are configured for accurate cost tracking.
”Duplicate events”
If using both LLM instrumentation and framework callbacks, you may see duplicate LLM call records. This is expected - one from the low-level instrumentation, one from the framework callback. The framework callback provides richer context (chain name, agent reasoning) while the low-level instrumentation provides precise token costs.
Example: Full stack tracking
See also