The new Temporal integration can run your Mastra workflows with automatic retries, long-running execution, scheduling, and durable state.
The standard Mastra workflow API remains the same. The integration converts each createWorkflow() into a Temporal workflow, and each createStep() into a Temporal activity.
Temporal is a good fit for workflows that orchestrate external APIs, run for hours or days, or need to survive worker restarts. It can run on your own infrastructure or as a hosted service.
Get started
Install the Temporal packages:
1npm install @mastra/temporal @temporalio/client @temporalio/worker @temporalio/envconfigRequires @mastra/core@1.32.0 or later, added in PR #15789.
Running Mastra workflows on Temporal consists of three parts:
- A Temporal client instance to convert the workflow functions
- An import swap in workflow files
- A long-lived worker process to run them
Temporal client instance
Create a Temporal client instance that binds Mastra's createWorkflow and createStep to a Temporal task queue. (typically created at src/mastra/temporal/index.ts)
Import swap
Import createWorkflow and createStep from the Temporal client instance:
1// resolves to src/mastra/temporal/index.ts
2import { createWorkflow, createStep } from "../temporal";
3
4const incrementStep = createStep({
5 id: "increment-step"
6 //...
7});
8
9export const incrementWorkflow = createWorkflow({
10 id: "increment-workflow"
11 // ...
12})
13 .then(incrementStep)
14 .commit();Worker process
Create a worker process that polls the Temporal task queue and runs your workflows.
Config options
The Temporal instance and worker process can accept additional configuration options including:
startToCloseTimeoutfor per-step timeoutsmaxConcurrentActivityTaskExecutionsfor worker concurrencyshutdownForceTimefor graceful shutdown
For more information and full configuration options, see:
@mastra/temporal is experimental. The API may change between releases. See the package README for the current state.
