UNPKG

@teerai/agent-toolkit

Version:

TeerAI Agent Toolkit - Tools and middleware for AI agents

67 lines (53 loc) 3.13 kB
# Teer Agent Toolkit - AI SDK The AI SDK module of the Teer Agent Toolkit provides middleware for the Vercel AI SDK, allowing you to track token usage and other metrics for AI model calls. ## Usage ```typescript import { TeerAgentToolkit } from '@teerai/agent-toolkit/ai-sdk' import { openai } from '@ai-sdk/openai' import { generateText, wrapLanguageModel } from 'ai' // Initialize the Teer Agent Toolkit const teerAgentToolkit = new TeerAgentToolkit({ apiKey: process.env.TEER_API_KEY!, }) // Wrap the language model with the middleware const model = wrapLanguageModel({ model: openai('gpt-4o'), // Optional params // - functionId // - metadata middleware: teerAgentToolkit.middleware({ functionId: 'chat-completion', metadata: { userId: 'user-123', sessionId: 'session-123', organizationId: 'org-123', }, }), }) // Use the wrapped model const result = await generateText({ model, prompt: 'Hello, world!', }) ``` ## Configuration Options ### TeerAgentToolkit The base configuration options for initializing the toolkit. | Property | Type | Required | Default | Description | | --------------- | -------------- | -------- | ------- | -------------------------------------------- | | `apiKey` | `string` | Yes | - | API key for authentication with Teer backend | | `baseURL` | `string` | No | - | Custom base URL for API requests | | `debug` | `boolean` | No | `false` | Enable debug logging | | `flushInterval` | `number` | No | `5000` | Flush interval in milliseconds | | `customFetch` | `typeof fetch` | No | - | Custom fetch implementation | ### middleware Optional configuration for enhanced tracking and analytics. Use `functionId` to identify specific operations and use dot paths | Property | Type | Required | Default | Description | | -------------- | --------------------- | -------- | ------- | ------------------------------------------------------------------------------- | | `functionId` | `string` | No | - | Function identifier to track which function is generating responses | | `traceId` | `string` | No | - | Trace ID to track the request | | `spanId` | `string` | No | - | Span ID to track the request | | `parentSpanId` | `string` | No | - | Parent span ID to track the request | | `metadata` | `Record<string, any>` | No | - | Additional metadata to annotate tracking data with (e.g. userId, sessionId etc) | | `timestamp` | `Date` | No | - | Timestamp of the request |