Mastra Integration
Learn how to integrate Mastra agents with the Scenario testing framework
Mastra agents work seamlessly with Scenario through the AgentAdapter[ts]
interface. The key is managing conversation history and handling the iterative agent execution.
Basic Integration Pattern
Given a Mastra agent with tools and memory:
import { Agent } from '@mastra/core/agent';
import { Memory } from '@mastra/memory';
import { LibSQLStore } from '@mastra/libsql';
export const weatherAgent = new Agent({
name: 'Weather Agent',
instructions: 'You are a helpful weather assistant...',
model: openai('gpt-4o-mini'),
tools: { weatherTool },
memory: new Memory({
storage: new LibSQLStore({ url: 'file:../mastra.db' }),
}),
});
You can integrate it with Scenario like this:
import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
const weatherAgent: AgentAdapter = {
role: AgentRole.AGENT,
call: async (input) => {
const result = await weatherAgentMastra.generate(input.messages);
return result.response.messages;
},
};
Full Example Project
For a complete working example with a customer support agent, including tools, system prompts, and comprehensive tests, check out the create-agent-app project.
Next Steps
- Explore Scenario Basics for advanced testing patterns
- Learn about Scripted Simulations for precise control
- Check out more Agent Integration patterns for other frameworks