Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Workflow.then()

The .then() method creates a sequential dependency between workflow steps, ensuring steps execute in a specific order.

UsageDirect link to Usage

workflow.step(stepOne).then(stepTwo).then(stepThree);

ParametersDirect link to Parameters

step:

Step | string
The step instance or step ID that should execute after the previous step completes

ReturnsDirect link to Returns

workflow:

LegacyWorkflow
The workflow instance for method chaining

ValidationDirect link to Validation

When using then:

  • The previous step must exist in the workflow
  • Steps cannot form circular dependencies
  • Each step can only appear once in a sequential chain

Error HandlingDirect link to Error Handling

try {
workflow
.step(stepA)
.then(stepB)
.then(stepA) // Will throw error - circular dependency
.commit();
} catch (error) {
if (error instanceof ValidationError) {
console.log(error.type); // 'circular_dependency'
console.log(error.details);
}
}

On this page