Creating a Simple Workflow
A workflow allows you to define and execute sequences of operations in a structured path. This example shows a workflow with a single step.
import { Step, Workflow } from "@mastra/core/workflows";
import { z } from "zod";
const myWorkflow = new Workflow({
name: "my-workflow",
triggerSchema: z.object({
input: z.number(),
}),
});
const stepOne = new Step({
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