Run.stream()
The .stream() method allows you to monitor the execution of a workflow run, providing real-time updates on the status of steps.
Usage exampleDirect link to Usage example
const run = await workflow.createRunAsync();
const { stream } = await run.stream({
inputData: {
value: "initial data",
},
});
ParametersDirect link to Parameters
inputData?:
z.infer<TInput>
Input data that matches the workflow's input schema
runtimeContext?:
RuntimeContext
Request Context data to use during workflow execution
tracingContext?:
TracingContext
AI tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.
currentSpan?:
AISpan
Current AI span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.
tracingOptions?:
TracingOptions
Options for AI tracing configuration.
metadata?:
Record<string, any>
Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.
ReturnsDirect link to Returns
stream:
ReadableStream<StreamEvent>
A readable stream that emits workflow execution events in real-time
getWorkflowState:
() => Promise<WorkflowResult<TState, TOutput, TSteps>>
A function that returns a promise resolving to the final workflow result
traceId?:
string
The trace ID associated with this execution when AI tracing is enabled. Use this to correlate logs and debug execution flow.
Extended usage exampleDirect link to Extended usage example
const { getWorkflowState } = await run.stream({
inputData: {
value: "initial data",
},
});
const result = await getWorkflowState();
Stream EventsDirect link to Stream Events
The stream emits various event types during workflow execution. Each event has a type field and a payload containing relevant data:
start: Workflow execution beginsstep-start: A step begins executiontool-call: A tool call is initiatedtool-call-streaming-start: Tool call streaming beginstool-call-delta: Incremental tool output updatesstep-result: A step completes with resultsstep-finish: A step finishes executionfinish: Workflow execution completes