Skip to Content
ReferenceWorkflowsWorkflow Class

Workflow Class

The Workflow class enables you to create state machines for complex sequences of operations with conditional branching and data validation.

Usage example

src/mastra/workflows/test-workflow.ts
import { createWorkflow } from "@mastra/core/workflows"; import { z } from "zod"; export const workflow = createWorkflow({ id: "test-workflow", inputSchema: z.object({ value: z.string(), }), outputSchema: z.object({ value: z.string(), }) })

Constructor parameters

id:

string
Unique identifier for the workflow

inputSchema:

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

outputSchema:

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

Workflow status

A workflow’s status indicates its current execution state. The possible values are:

success:

string
All steps finished executing successfully, with a valid result output

failed:

string
Workflow encountered an error during execution, with error details available

suspended:

string
Workflow execution is paused waiting for resume, with suspended step information

Extended usage example

src/test-run.ts
import { mastra } from "./mastra"; const run = await mastra.getWorkflow("workflow").createRunAsync(); const result = await run.start({...}); if (result.status === "suspended") { const resumedResult = await run.resume({...}); }