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 example
const run = await workflow.createRunAsync();
const stream = await run.stream({
inputData: {
value: "initial data",
},
});
Parameters
inputData?:
z.infer<TInput>
Input data that matches the workflow's input schema
runtimeContext?:
RuntimeContext
Runtime context data to use during workflow execution
Returns
stream:
ReadableStream<StreamEvent>
A readable stream that emits workflow execution events in real-time
getWorkflowState:
() => Promise<WorkflowResult<TOutput, TSteps>>
A function that returns a promise resolving to the final workflow result
Extended usage example
const { getWorkflowState } = await run.stream({
inputData: {
value: "initial data"
}
});
const result = await getWorkflowState();
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