---
title: Fix and verify Mastra agent behavior with Converra
description: Send completed Mastra text conversations to Converra, test prompt fixes, and verify the approved change on production traffic.
---

# Mastra integration

Use Converra to turn Mastra agent conversations into tested behavior fixes. It diagnoses the failing turn, generates a bounded change, compares it against the current agent in simulation, and reports a production verdict after you approve the change: **verified, not fixed, or confounded**.

## Install

```bash
npm install converra @mastra/core
```

Use a Node.js version supported by Mastra and an ESM project. Set `CONVERRA_API_KEY` and `OPENAI_API_KEY` on the server. Use your existing model in `provider/model` form, for example `openai/gpt-4o`.

## Send a completed text interaction

```typescript
import { Agent } from '@mastra/core/agent';
import { Converra } from 'converra';

const apiKey = process.env.CONVERRA_API_KEY;
if (!apiKey) throw new Error('Set CONVERRA_API_KEY');
const converra = new Converra({ apiKey });

const agent = new Agent({
  id: 'refund-support',
  name: 'Refund support',
  instructions: 'Ask for an order number before discussing refund eligibility.',
  model: 'openai/gpt-4o',
});

const userText = 'Can I get a refund?';
const response = await agent.generate(userText);
if (!response.text) throw new Error('Expected a text response');

const run = await converra.send({
  agent: 'Refund support',
  messages: [
    { role: 'user', content: userText },
    { role: 'assistant', content: response.text },
  ],
  metadata: { source: 'mastra' },
});

console.log(run.conversationId);
```

Replace the example model with the one your application already uses. This example sends text conversations explicitly; it is not a Mastra observability exporter. It does not export intermediate tool calls, workflow steps, or memory. Include actual tool evidence through [enriched SDK messages](/sdk) when diagnosing a tool-using agent. Avoid instrumenting the same interaction twice.

In an existing Mastra application, use the agent registered in your own Mastra instance. Keep the current instructions configured in Converra before optimizing. For multi-turn chat, retain `run.conversationId` and append new exchanges with `conversationId`, closing the conversation with `status: 'completed'`.

## Test a fix and verify production

Connect [Converra MCP to Claude Code, Codex, or Cursor](/mcp/coding-agents). Inspect the failed conversation, generate a prompt or configuration fix, compare it against the baseline on shared personas, and check regression scenarios. You approve the change your Mastra application applies.

Continue sending conversations after the change. `get_deployment_impact` and `get_verification_evidence` report what happened to the targeted failure. Read the [verdict rules and limits](/mcp/coding-agents#how-a-verdict-is-decided) before treating a result as verified.

## References

Reviewed 2026-10-15: [Mastra agent documentation](https://mastra.ai/docs/agents/overview) for `Agent`, `generate`, and the text result; [Converra Node.js SDK](/sdk) version 0.8.1 for `send` and `conversationId`.
