@agentlair/vercel-ai
v0.1.1
Published
AgentLair telemetry integration for the Vercel AI SDK. Captures tool calls, completions, errors, and token usage — feeds your agent's behavioral trust profile.
Maintainers
Readme
@agentlair/vercel-ai
AgentLair telemetry integration for the Vercel AI SDK. Captures tool calls, completions, errors, and token usage from your AI SDK generations and forwards them to AgentLair to build your agent's behavioral trust profile.
Zero runtime dependencies. Works with any AI SDK model provider.
Install
npm install @agentlair/vercel-ai
# or
bun add @agentlair/vercel-aiQuick start
bun add @agentlair/vercel-ai ai @ai-sdk/openaiimport { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { createAgentLairExporter } from "@agentlair/vercel-ai";
const agentlair = createAgentLairExporter({
apiKey: process.env.AGENTLAIR_API_KEY!, // al_live_...
agentId: "my-agent",
});
const { text } = await generateText({
model: openai("gpt-4o-mini"),
prompt: "Summarise last week's sales",
tools: { ... },
experimental_telemetry: { isEnabled: true, tracer: agentlair },
});
await agentlair.shutdown(); // flush before process exitCaptures tool call timing, token usage, and session lifecycle — no prompt content leaves your process. Get your API key at agentlair.dev.
What gets captured
| AI SDK event | AgentLair event | Category | Data |
|---|---|---|---|
| onStart | generation_start | session | model, provider, temperature, tool count |
| onToolCallStart | {toolName} | tool | tool name, call ID |
| onToolCallFinish | {toolName}_complete | tool | duration, success/failure, error |
| onStepFinish | step_complete | session | token usage, finish reason, tool call count |
| onFinish | generation_complete | session | total token usage, finish reason |
Events are batched and flushed every 5 seconds (configurable). Buffer auto-flushes when it reaches 50 events.
Configuration
const agentlair = createAgentLairExporter({
// Required
apiKey: 'al_live_...', // Your AgentLair API key
agentId: 'my-agent', // Agent identifier for event attribution
// Optional
baseUrl: 'https://agentlair.dev', // API base URL
flushInterval: 5000, // Batch flush interval (ms)
maxBufferSize: 50, // Force-flush threshold
sessionId: 'custom-session-id', // Group events by session
timeout: 3000, // Request timeout (ms)
captureInputs: false, // Log input metadata (prompt length, message count)
captureOutputs: false, // Log output metadata (response length)
onError: (err) => console.error(err), // Error handler (swallowed by default)
});Behavioral attestation
Events submitted through this adapter feed AgentLair's trust engine. Your agent's trust score reflects:
- Consistency of tool usage patterns over time
- Transparency through complete audit trails
- Behavioral adherence to declared capabilities
View your agent's trust profile at https://agentlair.dev/badge/{agentId}/score.json or embed a badge in your README.
License
MIT
