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.step()

The .step() method adds a new step to the workflow, optionally configuring its variables and execution conditions.

UsageDirect link to Usage

workflow.step({
id: "stepTwo",
outputSchema: z.object({
result: z.number(),
}),
execute: async ({ context }) => {
return { result: 42 };
},
});

ParametersDirect link to Parameters

stepConfig:

Step | StepDefinition | string
Step instance, configuration object, or step ID to add to workflow

options?:

StepOptions
Optional configuration for step execution

StepDefinitionDirect link to StepDefinition

id:

string
Unique identifier for the step

outputSchema?:

z.ZodSchema
Schema for validating step output

execute:

(params: ExecuteParams) => Promise<any>
Function containing step logic

StepOptionsDirect link to StepOptions

variables?:

Record<string, VariableRef>
Map of variable names to their source references

when?:

StepCondition
Condition that must be met for step to execute

On this page