Skip to main content
This guide will help you set up the Agent Governance SDK and start monitoring your AI agents quickly.

Prerequisites

  • Node.js version 18 or higher
  • An Agent Governance API key and organization ID
  • An existing AI agent using Anthropic or OpenAI

Installation

Install the SDK using your preferred package manager:
npm install @agent-governance/node

Basic Setup

1. Initialize the Monitor

Create a new AgentMonitor instance with your configuration:
import { AgentMonitor } from '@agent-governance/node';

const monitor = new AgentMonitor({
  apiKey: process.env.AGENT_GOVERNANCE_API_KEY,
  organizationId: process.env.AGENT_GOVERNANCE_ORG_ID,
  environment: 'development',
  enableComplianceChecks: true,
  enableLogging: true
});
Store your API credentials in environment variables for security. Never commit API keys to version control.

2. Register Your Agent

Before tracking interactions, register your agent with the monitoring system:
await monitor.registerAgent({
  id: 'customer-service-agent',
  name: 'Customer Service Assistant',
  category: 'tool_calling',
  specialty: 'customer_service',
  version: '1.0.0',
  llmProvider: 'anthropic',
  model: 'claude-3-5-sonnet-20241022',
  description: 'AI assistant for customer service inquiries',
  complianceSettings: {
    sr11_7_enabled: true,
    fair_lending_monitoring: true,
    bsa_aml_checks: true
  }
});

3. Track Interactions

Start monitoring your agent’s conversations:
const sessionId = 'session-' + Date.now();
const agentId = 'customer-service-agent';

// Start a new conversation
monitor.trackConversationStart(agentId, sessionId);

// Track user message
monitor.trackUserMessage(agentId, sessionId, 'What is my account balance?');

// Track agent response
monitor.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 done
await monitor.shutdown();

LLM Integration Setup

For automatic monitoring without manual tracking, wrap your existing LLM clients:

Anthropic Integration

import { AnthropicAgentMonitor } from '@agent-governance/node';
import Anthropic from '@anthropic-ai/sdk';

// Initialize the monitor
const monitor = new AnthropicAgentMonitor({
  apiKey: process.env.AGENT_GOVERNANCE_API_KEY,
  organizationId: process.env.AGENT_GOVERNANCE_ORG_ID
});

// Register your agent
await monitor.registerAgent({
  id: 'banking-assistant',
  name: 'Banking Assistant',
  category: 'tool_calling',
  version: '1.0.0',
  llmProvider: 'anthropic',
  model: 'claude-3-5-sonnet-20241022'
});

// Wrap the Anthropic client
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const monitoredAnthropic = monitor.wrapAnthropic(anthropic, 'banking-assistant');

// Use normally - all interactions are automatically tracked
const response = await monitoredAnthropic.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  messages: [{ role: 'user', content: 'Help me with my account' }],
  sessionId: 'session-123' // Optional: link events to a session
});

OpenAI Integration

import { OpenAIAgentMonitor } from '@agent-governance/node';
import OpenAI from 'openai';

const monitor = new OpenAIAgentMonitor({
  apiKey: process.env.AGENT_GOVERNANCE_API_KEY,
  organizationId: process.env.AGENT_GOVERNANCE_ORG_ID
});

await monitor.registerAgent({
  id: 'gpt-assistant',
  name: 'GPT Assistant',
  category: 'persona',
  version: '1.0.0',
  llmProvider: 'openai',
  model: 'gpt-4'
});

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const monitoredOpenAI = monitor.wrapOpenAI(openai, 'gpt-assistant');

const response = await monitoredOpenAI.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello!' }]
});

Configuration Options

Customize the monitoring behavior with these configuration options:
const monitor = new AgentMonitor({
  apiKey: 'your-api-key',
  organizationId: 'your-org-id',

  // Optional configurations
  endpoint: 'https://api.aiagentshouse.com', // Custom endpoint
  environment: 'production', // 'development', 'staging', or 'production'
  batchSize: 100, // Events per batch (1-1000)
  flushInterval: 5000, // Milliseconds between flushes (min 100)
  enableComplianceChecks: true, // Enable real-time compliance monitoring
  enableLogging: true, // Enable SDK logging
  logLevel: 'info', // 'debug', 'info', 'warn', or 'error'
  retryAttempts: 3, // Number of retry attempts for failed requests
  retryDelay: 1000 // Delay between retries in milliseconds
});

Compliance Monitoring

When enableComplianceChecks is enabled, the SDK automatically scans interactions for:
  • PII Detection: Emails, phone numbers, SSNs, and other sensitive data
  • Fair Lending: Discriminatory language and bias indicators
  • BSA/AML: Suspicious activity keywords and patterns
Compliance violations are automatically flagged and included in your event data for review.

Complete Example

Here’s a complete working example that demonstrates all key features:
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 agent
await 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 conversation
const 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 shutdown
await monitor.flush();
await monitor.shutdown();
}

basicExample().catch(console.error);

Next Steps

Now that you have the basics working:

Compliance Engine

Learn about built-in compliance monitoring

Manual Tracking

Detailed event tracking capabilities

Configuration

Advanced configuration options

API Reference

Complete API documentation
Check out the examples folder in the SDK repository for more detailed use cases and integration patterns.