TypeScript SDK

TypeScript SDK

Node.js 애플리케이션을 위한 AgentOps TypeScript SDK를 시작하는 방법을 소개해요. 현대 SDK와 레거시 SDK의 설치, 사용법, 그리고 도움 받는 방법까지 알아볼게요.

출처: 문서

본문

TypeScript SDK

AgentOps는 두 가지 SDK 옵션을 통해 TypeScript/JavaScript를 지원합니다.

현대 TypeScript SDK (권장)

현대 TypeScript SDK는 OpenTelemetry 표준 위에 구축되었으며 AI 에이전트를 위한 포괄적인 계측을 제공합니다.

설치 (Installation)

npm install agentops

퀵 스타트 (Quick Start)

import { agentops } from 'agentops';

// Initialize with environment variable AGENTOPS_API_KEY
await agentops.init();

// Or pass API key explicitly
await agentops.init({
  apiKey: ***
});

// Your AI agent code here - instrumentation happens automatically!

기능 (Features)

  • 🔌 플러그인 아키텍처: 계측기의 동적 로딩과 설정
  • 🤖 GenAI 지원: OpenTelemetry GenAI 시맨틱 컨벤션 내장 지원
  • 📊 표준 준수: 모든 OpenTelemetry 호환 컬렉터로 내보내기
  • 🛠️ 프레임워크 무관: 여러 에이전트 프레임워크를 동시에 계측
  • 🔧 TypeScript 우선: 포괄적인 타입 정의가 포함된 완전한 TypeScript 지원

OpenAI Agents 통합

SDK는 OpenAI Agents SDK에 대한 일급 지원을 제공합니다.

import { agentops } from 'agentops';
import { Agent, run } from '@openai/agents';

// Initialize AgentOps first
await agentops.init();

// Create your agent with tools and instructions
const agent = new Agent({
  name: 'My Assistant',
  instructions: 'You are a helpful assistant.',
  tools: [/* your tools */],
});

// Run the agent - instrumentation happens automatically
const result = await run(agent, "Hello, how can you help me?");
console.log(result.finalOutput);

자동으로 캡처합니다.

  • Agent Lifecycle: 에이전트 생성, 실행, 완료 추적
  • LLM Generation: 모델 요청, 응답, 토큰 사용량 캡처
  • Function Calls: 도구 사용과 함수 실행 모니터링
  • Audio Processing: 음성-텍스트와 텍스트-음성 작업 관찰
  • Handoffs: 에이전트 간 통신과 워크플로우 전환 추적

디버그 로깅 (Debug Logging)

상세한 계측 로그를 활성화하세요.

DEBUG=agentops:* node your-app.js

레거시 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-...ey",
    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 functions
function customFunction(x: string) {
    console.log(x);
    return 5;
}

const wrappedFunction = agentops.wrap(customFunction);
wrappedFunction("hello");

// Run your agent
chat().then(() => {
    agentops.endSession("Success");
});

도움 받기 (Getting Help)

더 알아보기 (Learn more)