Table of Contents
🌏 中文版
Mastra is an open-source agent framework for TypeScript and Node.js teams. It combines agents, tools, MCP, workflows, memory, tracing, scorers, and a local Studio rather than merely wrapping a model SDK.
That is attractive in an existing Next.js, Node.js, or Cloudflare project: schemas stay in TypeScript and no separate Python service is required. The tradeoff is a broad framework surface.
Agents and tools meet at schemas
An Agent combines instructions, a model, tools, and memory. A Tool defines an input schema and executor. The tools guide can load MCP tools or expose a Mastra agent as an MCP tool.
import { Agent } from '@mastra/core/agent';
import { createTool } from '@mastra/core/tools';
import { z } from 'zod';
const lookup = createTool({
id: 'lookup-order',
description: 'Look up an order',
inputSchema: z.object({ id: z.string() }),
execute: async ({ id }) => ({ id, status: 'shipped' }),
});
export const supportAgent = new Agent({
name: 'Support agent', instructions: 'Use tools before answering.',
model: 'openai/gpt-5-mini', tools: { lookup },
});
Schemas reject malformed input, not unauthorized access. Tools must obtain verified identity from runtime context rather than trust customer IDs supplied by the model.
Workflows own deterministic paths
Mastra Workflows compose typed steps with sequential, parallel, branch, and loop control, plus suspend and resume. Use an Agent when the model should choose the next action; use a Workflow when order, error handling, and approval are explicit. Persisted state still does not make external side effects idempotent.
Memory, tracing, and scorers close different loops
Memory changes the context of future runs. Tracing explains what happened. Scorers measure whether the outcome met a criterion. Before production, verify storage ownership, trace export, and sensitive-data redaction; a convenient Studio should not be the only audit record.
Overall
Mastra fits TypeScript teams building both agents and resumable workflows. For one structured model call, an AI SDK plus Zod is thinner. Evaluate Mastra with a three-step workflow—read, agent decision, approval and write—then restart the process and test resume. See the agent framework guide for alternatives.
References
Loading...