Skip to Content
ExamplesWorkflows (Legacy)Creating a Workflow

Creating a Simple Workflow (Legacy)

A workflow allows you to define and execute sequences of operations in a structured path. This example shows a legacy workflow with a single step.

import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy"; import { z } from "zod"; const myWorkflow = new LegacyWorkflow({ name: "my-workflow", triggerSchema: z.object({ input: z.number(), }), }); const stepOne = new LegacyStep({ id: "stepOne", inputSchema: z.object({ value: z.number(), }), outputSchema: z.object({ doubledValue: z.number(), }), execute: async ({ context }) => { const doubledValue = context?.triggerData?.input * 2; return { doubledValue }; }, }); myWorkflow.step(stepOne).commit(); const { runId, start } = myWorkflow.createRun(); const res = await start({ triggerData: { input: 90 }, }); console.log(res.results);





View Example on GitHub