Mastra
Type: full-code · Vendor: Kepler Software, Inc. · Language: TypeScript · License: Apache-2.0 (ee/ directories under Mastra Enterprise License) · Status: active · Status in practice: emerging · First released: 2024-08-06
Provide a TypeScript-native framework for AI agents and multi-step workflows, where Agents run an LLM tool-calling loop bounded by maxSteps, Workflows give graph-based control flow with suspend/resume snapshots, and integrations cover MCP (client+server), RAG, memory, voice, and evals.
Description. Mastra is an Apache-2.0 TypeScript framework from Kepler Software, Inc. ('from the team behind Gatsby', per repo). It ships two execution shapes: Agents which 'reason about goals, decide which tools to use, retain conversation memory, and iterate internally until the model emits a final answer or an optional stop condition is met' (docs/agents/overview), and Workflows which give 'full control over how tasks are broken down' via .then() / .branch() / .parallel() / .dountil() / .dowhile() / .foreach() over typed steps. Both can suspend and resume — snapshots persist to the configured storage provider across deployments and restarts. Integrates with 40+ model providers, exposes Mastra tools/agents/workflows over MCP via MCPServer (and consumes external MCP via MCPClient), and ships built-in evals (Scorers), memory, RAG, and voice (TTS/STT/STS).
Agent loop shape. Imperative tool-calling agent loop with explicit maxSteps cap (default 5). Starting v0.14.0 Mastra owns the loop directly rather than delegating to AI SDK. Workflows compose typed steps via graph operators (.then/.branch/.parallel/.dountil/.dowhile/.foreach) with suspend()/resume() snapshots. Workflows and agents compose — workflow steps can call agents, agents can be configured with sub-agents (supervisor pattern), agents can be exposed over MCP.
Primary use cases
- TypeScript-native agents with workflow orchestration
- long-running agents that pause and resume across deployments
- supervisor agents with subagents
- multi-channel voice + chat assistants
Key concepts
- Agent → react (docs) — Reasons about goals, uses tools, retains memory, iterates internally.
- Workflow (docs) — Graph-based orchestration with .then/.branch/.parallel/.dountil/.dowhile/.foreach.
- createTool → tool-use (docs) — Custom tools with Zod-typed input/output schemas.
- Memory (docs) — Working memory + semantic recall + conversation history across interactions.
- Suspend & Resume → agent-resumption (docs) — suspend() persists workflow state to storage; resume continues across deployments and restarts.
- Supervisor Agents → supervisor (docs) — Supervisor coordinates subagents (configured on the agents property); migration path from deprecated AgentNetwork.
- MCPServer / MCPClient → mcp (docs) — Bidirectional MCP — consume external MCP and expose Mastra tools/agents/workflows over MCP.
Patterns this full-code implements —
- ★★Agent Resumption
Workflow suspend()/resume() saves snapshot to storage provider; persists across deployments and restarts. README explicitly highlights this as a differentiator.
- ★★Agentic RAG
Vector Query Tool gives agents direct access to vector DB queries; the agent decides what to retrieve and how to filter. Upgraded from via-integration.
- ★★Model Context Protocol
Both directions: MCPClient consumes external MCP servers; MCPServer exposes Mastra tools/agents/workflows to MCP clients.
- ★★ReAct
Agent loop reasons → tool-calls → iterates. v0.14.0 brought the loop in-framework. Mastra docs don't use the literal 'ReAct' label.
- ★★Structured Output
Schema-based structured output via Zod / Valibot / ArkType / raw JSON Schema; Zod recommended for TS type inference.
- ★★Supervisor
Upgraded from limited per upstream docs — Mastra has a dedicated Supervisor Agents docs page and a migration guide deprecating AgentNetwork in favour of this exact pattern.
- ★★Tool Use
createTool() with description / inputSchema / outputSchema / execute. Tools can also come from MCP.
- ★★Evaluator-Optimizer
Scorers measure but do not close the loop to regenerate; live evals are async observation, not driven optimization. Could be re-classified as agent-as-judge.
Neighbourhood
Click any neighbour to follow the lineage. Scroll to zoom, drag to pan.