Run.start()
The .start() method starts a workflow run with input data, allowing you to execute the workflow from the beginning.
Usage exampleDirect link to Usage example
const run = await workflow.createRun()
const result = await run.start({
inputData: {
value: 'initial data',
},
})
ParametersDirect link to Parameters
inputData?:
requestContext?:
outputWriter?:
tracingContext?:
currentSpan?:
tracingOptions?:
rootSpanName?:
workflow run: '<id>' or agent run: '<id>' name. Use it to tell runs apart in trace lists.metadata?:
requestContextKeys?:
traceId?:
parentSpanId?:
nestUnderParent is true and a valid traceId is also set.nestUnderParent?:
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?:
outputOptions?:
includeState?:
perStep?:
paused. See Run one step at a time to continue it.ReturnsDirect link to Returns
result:
traceId?:
spanId?:
Extended usage exampleDirect 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 timeDirect 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'