Esta página se muestra en inglés. Una traducción al español está en curso.
WorkflowsMay 7, 2026·3 min de lectura

Mastra Workflows — TypeScript Agent Orchestration

Mastra Workflows defines multi-step typed agent flows in TypeScript. Build pipelines with .then(), .branch(), .parallel(), .while(). End-to-end type-safe.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Needs Confirmation · 52/100Política: confirmar
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: New
Entrada
Asset
Comando CLI universal
npx tokrepo install 25d28578-b0d5-497a-a626-972c0392849d
Introducción

Mastra Workflows is Mastra's typed orchestration primitive — chain .step().then().branch().parallel().while() to build multi-step agent pipelines where TypeScript inferring carries type-safety from the first input to the last output. Best for: production TypeScript agents that need readable, testable, observable workflows. Works with: Mastra 0.5+, Node 20+. Setup time: 5 minutes.


Define a workflow

import { Workflow, Step } from "@mastra/core";
import { z } from "zod";

const fetchData = new Step({
  id: "fetch",
  inputSchema: z.object({ url: z.string().url() }),
  outputSchema: z.object({ markdown: z.string() }),
  execute: async ({ context }) => {
    const res = await fetch(context.inputData.url);
    return { markdown: await res.text() };
  },
});

const summarize = new Step({
  id: "summarize",
  inputSchema: z.object({ markdown: z.string() }),
  outputSchema: z.object({ summary: z.string() }),
  execute: async ({ context, mastra }) => {
    const agent = mastra.getAgent("summarizer");
    const result = await agent.generate(`Summarize: ${context.inputData.markdown}`);
    return { summary: result.text };
  },
});

const workflow = new Workflow({
  name: "fetch-and-summarize",
  triggerSchema: z.object({ url: z.string().url() }),
}).step(fetchData).then(summarize).commit();

Branching

.then(classify)
.branch([
  [async ({ context }) => context.results.classify.kind === "bug",
   fixerStep],
  [async ({ context }) => context.results.classify.kind === "feature",
   plannerStep],
])

Run and stream

const { runId, start } = workflow.createRun();

start({ triggerData: { url: "https://example.com/blog" } });

// Subscribe to step events
workflow.watch(runId, (event) => {
  console.log(event.type, event.payload);
});

Each step's input/output is checkpointed — restart from the last successful step if a downstream step fails.


FAQ

Q: Mastra Workflows vs LangGraph? A: LangGraph is Python-first with a graph DSL. Mastra Workflows is TypeScript-first with a fluent chain API. Pick by language preference + ecosystem; both handle the same shape of problems.

Q: Is Mastra free? A: Yes — Mastra is open-source under Elastic License 2.0. Self-hostable. Mastra Cloud (managed deployment + observability) is paid.

Q: Can workflows call other workflows? A: Yes — step(otherWorkflow) embeds a workflow as a sub-step. Useful for shared sub-flows (e.g. validateAndCleanData reused across pipelines).


Quick Use

  1. npm create mastra@latest (scaffolds project + installs deps)
  2. Define Steps with inputSchema, outputSchema, execute (Zod-typed)
  3. Chain with new Workflow().step().then().commit(), then createRun().start()

Intro

Mastra Workflows is Mastra's typed orchestration primitive — chain .step().then().branch().parallel().while() to build multi-step agent pipelines where TypeScript inferring carries type-safety from the first input to the last output. Best for: production TypeScript agents that need readable, testable, observable workflows. Works with: Mastra 0.5+, Node 20+. Setup time: 5 minutes.


Define a workflow

import { Workflow, Step } from "@mastra/core";
import { z } from "zod";

const fetchData = new Step({
  id: "fetch",
  inputSchema: z.object({ url: z.string().url() }),
  outputSchema: z.object({ markdown: z.string() }),
  execute: async ({ context }) => {
    const res = await fetch(context.inputData.url);
    return { markdown: await res.text() };
  },
});

const summarize = new Step({
  id: "summarize",
  inputSchema: z.object({ markdown: z.string() }),
  outputSchema: z.object({ summary: z.string() }),
  execute: async ({ context, mastra }) => {
    const agent = mastra.getAgent("summarizer");
    const result = await agent.generate(`Summarize: ${context.inputData.markdown}`);
    return { summary: result.text };
  },
});

const workflow = new Workflow({
  name: "fetch-and-summarize",
  triggerSchema: z.object({ url: z.string().url() }),
}).step(fetchData).then(summarize).commit();

Branching

.then(classify)
.branch([
  [async ({ context }) => context.results.classify.kind === "bug",
   fixerStep],
  [async ({ context }) => context.results.classify.kind === "feature",
   plannerStep],
])

Run and stream

const { runId, start } = workflow.createRun();

start({ triggerData: { url: "https://example.com/blog" } });

// Subscribe to step events
workflow.watch(runId, (event) => {
  console.log(event.type, event.payload);
});

Each step's input/output is checkpointed — restart from the last successful step if a downstream step fails.


FAQ

Q: Mastra Workflows vs LangGraph? A: LangGraph is Python-first with a graph DSL. Mastra Workflows is TypeScript-first with a fluent chain API. Pick by language preference + ecosystem; both handle the same shape of problems.

Q: Is Mastra free? A: Yes — Mastra is open-source under Elastic License 2.0. Self-hostable. Mastra Cloud (managed deployment + observability) is paid.

Q: Can workflows call other workflows? A: Yes — step(otherWorkflow) embeds a workflow as a sub-step. Useful for shared sub-flows (e.g. validateAndCleanData reused across pipelines).


Source & Thanks

Built by Mastra. Licensed under Elastic License 2.0.

mastra-ai/mastra — ⭐ 13,000+

🙏

Fuente y agradecimientos

Built by Mastra. Licensed under Elastic License 2.0.

mastra-ai/mastra — ⭐ 13,000+

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados