const sessionId = 'session-' + Date.now();const agentId = 'customer-service-agent';// Start a new conversationmonitor.trackConversationStart(agentId, sessionId);// Track user messagemonitor.trackUserMessage(agentId, sessionId, 'What is my account balance?');// Track agent responsemonitor.trackAgentResponse(agentId, sessionId, 'I can help you check your account balance. Let me retrieve that information.');// Track tool usage (if applicable)monitor.trackToolCall( agentId, sessionId, 'get_account_balance', { accountId: 'user123' }, { balance: 1250.50, currency: 'USD' }, 150 // execution time in ms);// Clean shutdown when doneawait monitor.shutdown();
Here’s a complete working example that demonstrates all key features:
Copy
import { AgentMonitor } from '@agent-governance/node';async function basicExample() { const monitor = new AgentMonitor({ apiKey: process.env.AGENT_GOVERNANCE_API_KEY, organizationId: process.env.AGENT_GOVERNANCE_ORG_ID, environment: 'development', enableComplianceChecks: true});// Register agentawait monitor.registerAgent({ id: 'support-agent', name: 'Support Agent', category: 'persona', version: '1.0.0', llmProvider: 'anthropic', model: 'claude-3-5-sonnet-20241022', description: 'Customer support assistant'});// Track conversationconst sessionId = 'session-' + Date.now();monitor.trackConversationStart('support-agent', sessionId);monitor.trackUserMessage('support-agent', sessionId, 'I need help with my account');monitor.trackAgentResponse('support-agent', sessionId, 'I\'d be happy to help with your account. What specific assistance do you need?');// Flush events and shutdownawait monitor.flush();await monitor.shutdown();}basicExample().catch(console.error);