Skip to Content
ExamplesWorkflowsHuman in the Loop

Human in-the-loop Workflow

Use human-in-the-loop workflows to pause execution at specific steps for human input, decision-making, or tasks that require judgment beyond automation.

Suspend workflow

In this example, the workflow pauses until user input is received. Execution is suspended at a specific step and only resumes once the required confirmation is provided.

src/mastra/workflows/example-human-in-loop.ts
import { createWorkflow, createStep } from "@mastra/core/workflows"; import { z } from "zod"; const step1 = createStep({ id: "step-1", description: "passes value from input to output", inputSchema: z.object({ value: z.number() }), outputSchema: z.object({ value: z.number() }), execute: async ({ inputData }) => { const { value } = inputData; return { value }; } }); const step2 = createStep({ id: "step-2", description: "pauses until user confirms", inputSchema: z.object({ value: z.number() }), resumeSchema: z.object({ confirm: z.boolean() }), outputSchema: z.object({ value: z.number(), confirmed: z.boolean().optional() }), execute: async ({ inputData, resumeData, suspend }) => { const { value } = inputData; const { confirm } = resumeData ?? {}; if (!confirm) { await suspend({}); return { value: value }; } return { value: value, confirmed: confirm }; } }); export const humanInLoopWorkflow = createWorkflow({ id: "human-in-loop-workflow", inputSchema: z.object({ value: z.number() }), outputSchema: z.object({ value: z.number() }) }) .then(step1) .then(step2) .commit();

Workflows (Legacy)

The following links provide example documentation for legacy workflows: