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
Workflows (Legacy)
The following links provide example documentation for legacy workflows:
- Workflow (Legacy) with Sequential Steps
- Parallel Execution with Steps
- Branching Paths
- Workflow (Legacy) with Conditional Branching (experimental)
- Calling an Agent From a Workflow (Legacy)
- Tool as a Workflow step (Legacy)
- Workflow (Legacy) with Cyclical dependencies
- Data Mapping with Workflow Variables (Legacy)
- Human in the Loop Workflow (Legacy)
- Workflow (Legacy) with Suspend and Resume