Prerequisites
@anthropic-ai/sdk
package installed- Agent Governance SDK installed
- Valid Anthropic and Agent Governance API keys
Basic Setup
Installation
If you haven’t already, install both the Anthropic SDK and Agent Governance SDK:Initialize the Monitor
Use theAnthropicAgentMonitor
class for automatic Claude monitoring:
Register Your Agent
Register your Claude-powered agent with the monitoring system:Wrap the Anthropic Client
Wrap your existing Anthropic client to enable automatic monitoring:Usage Examples
Basic Conversation
With Tool Calls
The integration automatically tracks when Claude decides to call tools:Multi-turn Conversations
For conversations with multiple exchanges, including tool results:Automatic Tracking Features
The Anthropic integration automatically captures:Conversation Events
- Conversation Start: When a new session begins
- User Messages: All user inputs including text and tool results
- Agent Responses: Claude’s text responses
- Tool Calls: When Claude decides to use a tool
Performance Metrics
- Latency: Time taken for each API call
- Token Usage: Input, output, and total tokens
- Cost Calculation: Automatic cost tracking based on model pricing
- Response Quality: Optional quality scoring
Compliance Monitoring
- PII Detection: Scans for personal information in responses
- Fair Lending: Checks for discriminatory language
- BSA/AML: Monitors for suspicious activity indicators
Configuration Options
Session Management
Link related interactions by providing asessionId
:
Monitoring Options
Pass additional monitoring configuration:Custom User Identification
Track which customer is interacting with the agent:Cost Tracking
The integration automatically calculates costs based on Claude’s pricing:- Claude 3.5 Sonnet
- Claude 3 Haiku
- Claude 3 Opus
- Input: $3 per million tokens
- Output: $15 per million tokens
Error Handling
The wrapper preserves normal error handling while tracking errors:Banking Example
Here’s a complete example for a banking use case:Best Practices
Troubleshooting
Events not appearing in dashboard
Events not appearing in dashboard
Ensure you’ve properly configured your API key and organization ID. Check that
monitor.flush()
is called if you’re not seeing events immediately.Cost calculations seem incorrect
Cost calculations seem incorrect
Verify you’re using the correct model name. Cost calculations are based on the model specified in your API call.
Compliance violations not detected
Compliance violations not detected
Make sure
enableComplianceChecks: true
is set in your monitor configuration. Compliance checks only run on agent responses.Tool calls not being tracked
Tool calls not being tracked
Tool calls are automatically detected when Claude returns
tool_use
content. Ensure your tools are properly configured in your Claude API call.