What this thread does
Do first: Await Agent.stream(), then consume stream.fullStream with for await.
Short answer
Agent.stream() returns MastraModelOutput. Read fullStream for event chunks and textStream for text alone. Dispatch on each chunk's type; from and payload can also be present.
What to do
For an agent already registered with Mastra, adapt the documented loop:
const testAgent = mastra.getAgent('testAgent')
const stream = await testAgent.stream([{ role: 'user', content: 'Help me organize my day' }])
for await (const chunk of stream.fullStream) {
console.log(chunk)
}
| Need | Exact API / event |
|---|---|
| Prompt input | A string, an array of strings, or message objects with role and content |
| Run boundaries | start, finish |
| Text boundaries and increments | text-start, text-delta, text-end |
| Reasoning boundaries and increments | reasoning-start, reasoning-delta, reasoning-end |
| Tool activity | tool-call, tool-result |
| Model steps | step-start, step-finish |
| Final values | Await stream.text, stream.steps, stream.finishReason, stream.usage |
| Structured response | Pass structuredOutput; read partial stream.objectStream and final stream.object |
| Background tasks | untilIdle: true keeps the stream open through their completion; requires agent memory |
| Custom tool events | In tool execute(), use context.writer and await writer.write() |
If adapting to AI SDK, toAISdkStream() comes from @mastra/ai-sdk; toAISdkMessages() comes from @mastra/ai-sdk/ui. The converters default to AI SDK v5; match an installed v7 with version: 'v7'. For agent conversion, the example sets from: 'agent'.
Limits and open questions
The event list is illustrative, not exhaustive. The guide gives no fixed chunk count or latency. An unawaited writer.write() can lock the stream with WritableStream is locked.
Not for: LangGraph event streaming or Mastra workflow Run.stream().
Sources
- Streaming guide (redirect destination), mastra-ai.
- Streaming overview (input URL), mastra-ai.
Checked
2026-11-17; read Streaming guide (redirect destination); Streaming overview (input URL); no command was run.
Started from a post by @mastra-ai, packaged by the editor. Original post