Blog/

announcements

Announcing Mastra's improved agent orchestration with AI SDK v5 support

·

Aug 26, 2025

Mastra's always used Vercel's AI SDK for model routing and streaming.

With the recent release of AI SDK v5, rather than shipping a breaking change, we decided to upgrade our agent orchestration capabilities and add a streaming layer so our users didn't have to upgrade.

This implementation lets us take on more responsibility for the agent-specific parts.

Some highlights:

  • We have increased control over the tool calling and agent loop
  • We now handle both v4 and v5 message formats simultaneously. The playground model switcher auto-detects versions.
  • Our new streamVNext and generateVNext APIs are able to output v5 streams.

Let's dive in:

Increased control over tool calling and agent loop

Previously, we delegated control over tool calling and agent loop to AI SDK.

Starting v0.14.0 , Mastra now controls the agent loop, as well as tool calling. That means, we manage the orchestration between models and tools, handle retries with maxSteps, and control execution flow.

We've kept the same API to avoid any breaking changes. Expect additional features over the coming months now that we have increased control, e.g. specialized middleware and retry strategies, token optimization methods, and more human-in-the-loop controls.

How Mastra and AI SDK work together

We built our own streaming layer

We added our own streaming layer on top of supporting AI SDK's v4 and v5 streams. The key addition is nested streaming support—when an agent calls another agent nested in a tool, or a workflow calls an agent nested in a step, the constituent streams can now compose correctly.

Long-running tools can report progress without blocking. Nested agents stream their responses properly. This is crucial for production agent orchestration where you need to know what's happening at every level.

Configuring different streaming formats

Here are a few examples of how to output streams across the 3 formats:

AI SDK v4

Your v4 code works without changes.

 1export const mastra = new Mastra({
 2  agents: { weatherAgent },
 3});

AI SDK v5

 1const stream = await agent.streamVNext("Hello", { format: "aisdk" });
 2
 3// Stream in AI SDK v5 format
 4for await (const chunk of stream.fullStream) {
 5  if (chunk.type === "text-delta") {
 6    console.log(chunk.text);
 7  }
 8}
 9
10// Use with frontend frameworks
11return stream.toUIMessageStreamResponse();

Mastra's streaming layer

 1export const exampleAgent = new Agent({
 2  instructions: `...`,
 3  model: openai("gpt-4o-mini"), // AI SDK v5 provider (LanguageModelV2)
 4});
 5
 6const stream = await agent.streamVNext("Hello");
 7
 8// Stream in Mastra format
 9for await (const chunk of stream.fullStream) {
10  if (chunk.type === "text-delta") {
11    console.log(chunk.payload.text);
12  }
13}
14
15// Get complete output
16const fullOutput = await stream.getFullOutput();

Shoutout to Abhi, Tony, Tyler, and Caleb for dedicating the bulk of their time to this integration. Details in PR #6731 and PR #6909.

If you have questions or run into issues, we're on Discord and GitHub.

Stay up to date