Purpose: Standardized pattern for defining maintainable and testable workflow steps.
Last Updated: 2026-01-09
Workflow steps should be self-contained units that encapsulate their input/output schemas and execution logic. For complex workflows, steps should be moved to a dedicated steps/ directory and grouped by phase.
steps/phase1-load.ts, steps/phase2-process.ts).workflowStateSchema) in a schemas.ts file within the steps directory.stateSchema in createStep to ensure type safety when accessing the global workflow state.// src/mastra/workflows/v3/steps/phase1.ts
export const myStep = createStep({
id: 'my-step-id',
inputSchema: z.object({ ... }),
outputSchema: z.object({ ... }),
stateSchema: workflowStateSchema,
execute: async ({ inputData, state, mastra }) => {
console.log('🚀 Starting myStep...');
const result = await myTool.execute(inputData, { mastra });
return result;
},
});
Reference: src/mastra/workflows/v3/steps/
Related: