Question: How to Stream Text from Mastra Workflows to AI SDK Frontend?

Context

I'm using Mastra workflows with AI SDK 5.0 on the frontend. My workflow contains agent steps that stream text, and I need that text to appear in the UI.

Current Situation

  • Frontend: Using useChat from @ai-sdk/react which expects AI SDK formatted events (
    text-delta
    , etc.)
  • Backend: Fastify endpoint that streams a Mastra workflow
  • Problem: Using toAISdkFormat(workflowStream, { from: 'workflow' }) only emits workflow metadata (data-workflow parts), not the actual text content from agent steps
## What I've Discovered
The workflow stream emits workflow-step-output events that contain the text from agent steps, but toAISdkFormat with from: 'workflow' doesn't extract this text—it only provides workflow structure metadata.

I see that workflowRoute() exists in @mastra/ai-sdk, but it's designed for Mastra's built-in Hono server, not Fastify.

My Question

What's the recommended way to stream text content from Mastra workflow agent steps to an AI SDK frontend?

Options I'm considering:
  1. Manually transform the workflow stream to extract text from workflow-step-output events
  2. Use workflowRoute() handler somehow with Fastify
  3. Change the workflow structure to return agent output directly
  4. Something else I'm missing?
Is there a built-in Mastra utility for this, or is manual transformation the expected approach?
Was this page helpful?