Skip to Content

Step

The Step class defines individual units of work within a workflow, encapsulating execution logic, data validation, and input/output handling.

Usage

import { createStep } from "@mastra/core/workflows/vNext"; import { z } from "zod"; const processOrder = createStep({ id: "processOrder", inputSchema: z.object({ orderId: z.string(), userId: z.string(), }), outputSchema: z.object({ status: z.string(), orderId: z.string(), }), resumeSchema: z.object({ orderId: z.string(), }), suspendSchema: z.object({}), execute: async ({ inputData, mastra, getStepResult, getInitData, suspend, }) => { return { status: "processed", orderId: inputData.orderId, }; }, });

Constructor Parameters

id:

string
Unique identifier for the step

description:

string
Optional description of what the step does

inputSchema:

z.ZodType<any>
Zod schema defining the input structure

outputSchema:

z.ZodType<any>
Zod schema defining the output structure

resumeSchema:

z.ZodType<any>
Optional Zod schema for resuming the step

suspendSchema:

z.ZodType<any>
Optional Zod schema for suspending the step

execute:

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

ExecuteParams

inputData:

z.infer<TStepInput>
The input data matching the inputSchema

resumeData:

z.infer<TResumeSchema>
The resume data matching the resumeSchema, when resuming the step from a suspended state. Only exists if the step is being resumed.

mastra:

Mastra
Access to Mastra services (agents, tools, etc.)

getStepResult:

(stepId: string) => any
Function to access results from other steps

getInitData:

() => any
Function to access the initial input data of the workflow in any step

suspend:

() => Promise<void>
Function to pause workflow execution