Skip to main content

Run.start()

The .start() method starts a workflow run with input data, allowing you to execute the workflow from the beginning.

Usage example

const run = await workflow.createRunAsync();

const result = await run.start({
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

writableStream?:

WritableStream<ChunkType>
Optional writable stream for streaming workflow output

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.

outputOptions?:

OutputOptions
Options for AI tracing configuration.

includeState?:

boolean
Whether to include the workflow run state in the result.

Returns

result:

Promise<WorkflowResult<TState, TOutput, TSteps>>
A promise that resolves to the workflow execution result containing step outputs and status

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 example

import { RuntimeContext } from "@mastra/core/runtime-context";

const run = await workflow.createRunAsync();

const runtimeContext = new RuntimeContext();
runtimeContext.set("variable", false);

const result = await run.start({
inputData: {
value: "initial data",
},
runtimeContext,
});