This guide covers best practices and strategies for deploying your AI agent application with the Agent Governance SDK integrated. Proper deployment ensures that monitoring is reliable, performant, and secure in your production environment.

Pre-deployment Checklist

Before deploying to production, ensure you have:
  • Finalized Configuration: Your AgentMonitor configuration is set for production (e.g., appropriate batchSize, flushInterval, and logLevel).
  • Tested Thoroughly: Your application has been tested against a staging environment. See our Testing Guide for comprehensive strategies.
  • Managed Secrets: Your AGENT_GOVERNANCE_API_KEY and other secrets are managed securely and are not hardcoded.

Environment Configuration

It is critical to manage different configurations for your development, staging, and production environments. The most secure and flexible way to do this is with environment variables.
// config/monitor.js
import { AgentMonitor } from '@agent-governance/node';

function initializeMonitor() {
  const environment = process.env.NODE_ENV || 'development';

  const config = {
    apiKey: process.env.AGENT_GOVERNANCE_API_KEY,
    organizationId: process.env.AGENT_GOVERNANCE_ORG_ID,
    environment: environment,
  };

  if (environment === 'production') {
    // Production-optimized settings
    Object.assign(config, {
      enableLogging: false,
      logLevel: 'error',
      batchSize: 500,
      flushInterval: 15000, // 15 seconds
      retryAttempts: 5,
      retryDelay: 2000
    });
  } else {
    // Development/Staging settings
    Object.assign(config, {
      enableLogging: true,
      logLevel: 'debug',
      batchSize: 10,
      flushInterval: 2000 // 2 seconds
    });
  }

  return new AgentMonitor(config);
}

module.exports = { initializeMonitor };
<Warning>Never commit API keys or other secrets to your version control system. Use environment variables or a secret management service (like AWS Secrets Manager, HashiCorp Vault, or Doppler) to handle sensitive credentials.</Warning>Graceful ShutdownOne of the most critical aspects of deploying an application with the SDK is ensuring a graceful shutdown. The SDK buffers events in memory and sends them in batches. If your application process exits abruptly, any events still in the buffer will be lost.You must call await monitor.shutdown() to flush any remaining events before your process terminates.Example: Node.js HTTP Serverconst { initializeMonitor } = require('./config/monitor');
import http from 'http';

const monitor = initializeMonitor();
const server = http.createServer((req, res) => {
  // Your application logic here
  monitor.trackUserMessage('web-agent', 'session-123', 'Request received');
  res.end('Hello World!');
});

const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

async function gracefulShutdown() {
  console.log('Shutting down gracefully...');
  server.close(async () => {
    console.log('HTTP server closed.');
    try {
      await monitor.shutdown();
      console.log('Agent monitor flushed and shut down.');
      process.exit(0);
    } catch (error) {
      console.error('Error during monitor shutdown:', error);
      process.exit(1);
    }
  });
}

// Listen for termination signals
process.on('SIGTERM', gracefulShutdown);
process.on('SIGINT', gracefulShutdown);

Deployment Strategies

The Agent Governance SDK is a standard Node.js library and can be deployed in any environment that supports Node.js.