Skip to Content

Streaming Events

Streaming from agents or workflows provides real-time visibility into either the LLM’s output or the status of a workflow run. This feedback can be passed directly to the user, or used within applications to handle workflow status more effectively, creating a smoother and more responsive experience.

Events emitted from agents or workflows represent different stages of generation and execution, such as when a run starts, when text is produced, or when a tool is invoked.

Event types

Below is a complete list of events emitted from .streamVNext(). Depending on whether you’re streaming from an agent or a workflow, only a subset of these events will occur:

  • start: Marks the beginning of an agent or workflow run.
  • step-start: Indicates a workflow step has begun execution.
  • text-delta: Incremental text chunks as they’re generated by the LLM.
  • tool-call: When the agent decides to use a tool, including the tool name and arguments.
  • tool-result: The result returned from tool execution.
  • step-finish: Confirms that a specific step has fully finalized, and may include metadata like the finish reason for that step.
  • finish: When the agent or workflow completes, including usage statistics.

Inspecting agent streams

Iterate over the stream with a for await loop to inspect all emitted event chunks.

const testAgent = mastra.getAgent("testAgent"); const stream = await testAgent.streamVNext([ { role: "user", content: "Help me organize my day" }, ]); for await (const chunk of stream) { console.log(chunk); }

See Agent.streamVNext() for more information.

Example agent output

Below is an example of events that may be emitted. Each event always includes a type and can include additional fields like from and payload.

{ type: 'start', from: 'AGENT', // .. } { type: 'step-start', from: 'AGENT', payload: { messageId: 'msg-cdUrkirvXw8A6oE4t5lzDuxi', // ... } } { type: 'tool-call', from: 'AGENT', payload: { toolCallId: 'call_jbhi3s1qvR6Aqt9axCfTBMsA', toolName: 'testTool' // .. } }

Inspecting workflow streams

Iterate over the stream with a for await loop to inspect all emitted event chunks.

const testWorkflow = mastra.getWorkflow("testWorkflow"); const run = await testWorkflow.createRunAsync(); const stream = await run.streamVNext({ inputData: { value: "initial data" } }); for await (const chunk of stream) { console.log(chunk); }

Example workflow output

Below is an example of events that may be emitted. Each event always includes a type and can include additional fields like from and payload.

{ type: 'start', runId: '221333ed-d9ee-4737-922b-4ab4d9de73e6', from: 'WORKFLOW', // ... } { type: 'step-start', runId: '221333ed-d9ee-4737-922b-4ab4d9de73e6', from: 'WORKFLOW', payload: { stepName: 'step-1', args: { value: 'initial data' }, stepCallId: '9e8c5217-490b-4fe7-8c31-6e2353a3fc98', startedAt: 1755269732792, status: 'running' } }