Get started with the AgentOps TypeScript SDK for Node.js applications
TypeScript SDK
AgentOps provides TypeScript/JavaScript support through two SDK options:
Modern TypeScript SDK (Recommended)
The modern TypeScript SDK is built on OpenTelemetry standards and provides comprehensive instrumentation for AI agents.
Installation
npm install agentops
Quick Start
import { agentops } from 'agentops';// Initialize with environment variable AGENTOPS_API_KEYawait agentops.init();// Or pass API key explicitlyawait agentops.init({ apiKey: 'your-api-key'});// Your AI agent code here - instrumentation happens automatically!
Features
🔌 Plugin Architecture: Dynamic loading and configuration of instrumentors
🤖 GenAI Support: Built-in support for OpenTelemetry GenAI semantic conventions
📊 Standards Compliant: Exports to any OpenTelemetry-compatible collector
import { agentops } from 'agentops';import { Agent, run } from '@openai/agents';// Initialize AgentOps firstawait agentops.init();// Create your agent with tools and instructionsconst agent = new Agent({ name: 'My Assistant', instructions: 'You are a helpful assistant.', tools: [/* your tools */],});// Run the agent - instrumentation happens automaticallyconst result = await run(agent, "Hello, how can you help me?");console.log(result.finalOutput);
Automatically captures:
Agent Lifecycle: Track agent creation, execution, and completion
LLM Generation: Capture model requests, responses, and token usage
Function Calls: Monitor tool usage and function execution
Audio Processing: Observe speech-to-text and text-to-speech operations
Handoffs: Track agent-to-agent communication and workflow transitions
Debug Logging
Enable detailed instrumentation logs:
DEBUG=agentops:* node your-app.js
Legacy TypeScript SDK (Alpha)
The legacy TypeScript SDK has limited functionality compared to the Python SDK. The modern TypeScript SDK above is recommended for new projects.
Installation
npm install agentops
Usage
import OpenAI from "openai";import { Client } from 'agentops';const openai = new OpenAI();const agentops = new Client({ apiKey: "your-agentops-api-key", tags: ["typescript", "example"], patchApi: [openai] // Automatically record OpenAI calls});// Sample OpenAI call (automatically recorded)async function chat() { const completion = await openai.chat.completions.create({ messages: [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ], model: "gpt-3.5-turbo", }); return completion;}// Track custom functionsfunction customFunction(x: string) { console.log(x); return 5;}const wrappedFunction = agentops.wrap(customFunction);wrappedFunction("hello");// Run your agentchat().then(() => { agentops.endSession("Success");});