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
Direct link to Usage example

const run = await workflow.createRun()

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

Parameters
Direct link to Parameters

inputData?:

z.infer<TInput>
Input data that matches the workflow's input schema

requestContext?:

RequestContext
Request Context data to use during workflow execution

outputWriter?:

(chunk: TOutput) => Promise<void>
Optional asynchronous function to handle output chunks as they are produced

tracingContext?:

TracingContext
Tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.

currentSpan?:

Span
Current 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 Tracing configuration.

rootSpanName?:

string
Display name for the root span of this trace, replacing the default workflow run: '<id>' or agent run: '<id>' name. Use it to tell runs apart in trace lists.

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.

requestContextKeys?:

string[]
Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').

traceId?:

string
Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.

parentSpanId?:

string
Parent span ID to use for this execution (1-16 hexadecimal characters). Used to correlate with an external tracing system. Mastra does not treat it as a parent within Mastra storage unless nestUnderParent is true and a valid traceId is also set.

nestUnderParent?:

boolean
Set to true together with parentSpanId to attach this run as a child of that span inside the existing trace, for example an LLM judge under the run it scores. Exporters then keep the trace's own name, input, output, and tags. Leave unset when parentSpanId comes from your own tracing system. Ignored without a valid traceId and parentSpanId.

tags?:

string[]
Tags to apply to this trace. String labels for categorizing and filtering traces.

outputOptions?:

OutputOptions
Options for output configuration.

includeState?:

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

perStep?:

boolean
Run one step, then stop. The run reports status paused. See Run one step at a time to continue it.

Returns
Direct link to Returns

result:

Promise<WorkflowResult<TState, TInput, 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 Tracing is enabled. Use this to correlate logs and debug execution flow.

spanId?:

string
The root span ID associated with this execution when Tracing is enabled. Use this for span-level lookup and correlation.

Extended usage example
Direct link to Extended usage example

import { RequestContext } from '@mastra/core/request-context'

const run = await workflow.createRun()

const requestContext = new RequestContext()
requestContext.set('variable', false)

const result = await run.start({
inputData: {
value: 'initial data',
},
requestContext,
})

Run one step at a time
Direct link to Run one step at a time

Pass perStep: true to run only the next step. The run then reports status paused, and steps holds the output of the step that ran.

A paused run isn't suspended, so run.resume() throws This workflow run was not suspended. Calling run.start() again reruns the workflow from its first step. To continue, call run.timeTravel() on the same run with the ID of the next step. It reuses the stored results of the steps that already ran. If the previous step returned null, the next step receives {} instead, so return an object from steps that run before a timeTravel() continuation. The workflow needs configured storage, and the paused run's snapshot must still be in it. Otherwise, timeTravel() throws Snapshot not found for run <runId>:

const run = await workflow.createRun()

const first = await run.start({ inputData: { value: 1 }, perStep: true })
// first.status === 'paused'

// Run the next step only, then pause again
const second = await run.timeTravel({ step: 'step-2', perStep: true })
// second.status === 'paused'

// Run the remaining steps to completion
const final = await run.timeTravel({ step: 'step-3' })
// final.status === 'success'