Skip to content

Vercel AI SDK Integration

Learn how to integrate Vercel AI SDK agents with the Scenario testing framework

Vercel AI SDK agents work seamlessly with Scenario through the AgentAdapter[py] interface. The SDK provides a unified interface for building AI applications with streaming, tool calling, and structured outputs across multiple providers.

Basic Integration Pattern

Given a Vercel AI SDK agent:

import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
 
async function myAgent(prompt: string) {
  const result = await generateText({
    model: openai('gpt-4-turbo'),
    messages: [
      {
        role: 'system',
        content: 'You are a helpful AI assistant.',
      },
      {
        role: 'user',
        content: prompt,
      },
    ],
  });
 
  return result;
}

You can integrate it with Scenario like this:

import scenario, { type AgentAdapter } from '@langwatch/scenario';
 
const createMyAgentAdapter = (): AgentAdapter => {
  return {
    call: async (input) => {
      const result = await myAgent(input.messages.at(-1)?.content);
      return result.response.messages;
    },
  };
};

Next Steps