Mastra Workflows

Orchestrate complex, multi-step agentic processes

Mastra workflows let you define complex sequences of tasks using clear, structured steps rather than relying on the reasoning of a single agent. When a process needs to be repeatable, predictable and auditable, Mastra gives you full control over how tasks break down, how data moves between them and what gets executed when.

Precisely define your execution graph

When a single agent cannot reliably handle a multi-step process, Mastra workflows give you full control over execution. Define steps with input and output schemas, compose them into sequential, parallel, branching or looping execution graphs and handle errors at every stage. Mastra Studio visualizes the execution graph and runs it step by step.

Sequential

step.then(
  nextStep
)
sequential docs

Parallel

step.parallel([
 a,b            
])
parallel docs

Branch

step.branch([
  [cond1, step1],
  [cond2, step2]
])
branch docs

Loops

step.doWhile(cond)
loops docs

Compose with agentic primitives

Mastra workflows integrate directly with agents, tools, memory and MCP so every step can call the right primitive for the job. Nest workflows inside other workflows to reuse logic across processes. Persist state across steps so long-running workflows survive suspension and resumption.

Frequently asked questions

When should I use a Mastra workflow instead of an agent?

Mastra workflows are best for tasks that are clearly defined upfront and involve multiple steps with a specific execution order. Use a Mastra agent when the task is open-ended and requires reasoning to determine the next action. Use a workflow when you need fine-grained control over how data flows between steps.

What execution patterns do Mastra workflows support?

Mastra workflows support sequential, parallel, branching and looping execution patterns. Sequential steps pass outputs directly to the next step. Parallel steps run simultaneously and collect all outputs before continuing. Branching routes execution down different paths based on step outputs. Loops repeat steps until a condition is met.

Can Mastra workflows call agents and tools?

Mastra workflow steps can call registered agents or execute tools directly. Use agents within workflow steps when a step requires open-ended reasoning. Use tools when a step requires a clearly defined, repeatable operation against an external API or service.

How does state management work in Mastra workflows?

Mastra workflows support shared state across steps without passing values through every step's input and output schemas. Use state for tracking progress, accumulating results or sharing configuration across the entire workflow. State persists across suspension and resumption for long-running workflows.

How do I run Mastra workflows in production?

Mastra workflows run using the built-in execution engine by default. For production workloads requiring managed infrastructure, Mastra workflows deploy to Inngest, which provides step memoization, automatic retries and real-time monitoring. Mastra Cloud exposes workflows as REST API endpoints with automatic deployment on every push to your configured branch.

Ship better agents