TypeScript · Vercel AI SDK · 2026

Mastra — 写 TypeScript 的 Agent 框架

Python 有 LangChain、LlamaIndex、DSPy;TypeScript 长期缺一个"端到端"的 AI 框架。Mastra 由 Gatsby 创始团队打造,把 Agent、Tool、Workflow、Memory、RAG、Eval 装进同一套 TypeScript API,开发体验追上 Python 主流。本教程十章实战,带你从 npm create mastra 到生产 Agent。

Agent Tool · Zod Workflow Memory · Storage RAG Eval AI SDK 集成
开始学习 →
📊 10 章节 🧭 从 HelloAgent 到 Cloudflare/Vercel 部署 🚀 TypeScript AI 框架首选

课程目录

Agent、Tool、Workflow、Memory、RAG、Eval 一条线走通,给 TypeScript 一个完整 AI 技术栈

Chapter 01
Mastra 概览:TS 世界的 Agent 框架地貌
LangGraph / Vercel AI SDK / Mastra / Genkit 横向对比。Mastra 的定位:功能完备、本地优先、可部署到任意云。
选型定位
Chapter 02
快速上手:create mastra + 第一个 Agent
npm create mastra 脚手架,playground UI,本地热重载,一个 chefAgent 看全貌。
CLIPlayground
Chapter 03
Agent 与模型:统一接入 OpenAI、Anthropic、本地模型
Agent 类的 instructions / model / tools 三要素,AI SDK 4 provider 抽象,Ollama/OpenRouter 随意换。
AI SDKprovider
Chapter 04
Tools:Zod schema 的类型安全工具调用
createTool + Zod 描述参数;Tool 可以调 API、读数据库、查 RAG;错误处理与重试。
ZodTool Calling
Chapter 05
Workflows:多步骤有向图编排
createWorkflow 的 step / branch / parallel / until,比裸 while 循环更可观测。
WorkflowBranch
Chapter 06
Memory:线程 / 语义 / 工作记忆
Agent 不是无状态函数。Mastra Memory 提供对话线程、语义检索、长期工作记忆三层。
ThreadSemantic Recall
Chapter 07
RAG:Vector Store + 文档索引
内置 chunker、多种 vector store(pg、pinecone、qdrant、libsql)、query rewriter,几行代码做企业 RAG。
pgvectorChunking
Chapter 08
Evals:给 Agent 打分
内置 LLM-as-judge、answer-relevancy、faithfulness 等 Eval,CI 里跑回归。
Eval回归测试
Chapter 09
MCP 集成 + Observability
把 Mastra Agent 挂到 MCP Server,或反过来消费 MCP 工具;OpenTelemetry 上 Langfuse/Braintrust。
MCPOTel
Chapter 10
部署:Node/Cloudflare/Vercel
Mastra Dev Server 生产化、Cloudflare Workers adapter、Vercel Edge,数据库选型与成本。
CloudflareVercel
读前须知
本教程假设你熟悉 TypeScript、async/await,接触过 LLM API 调用。无需 LangChain 经验——Mastra 理念接近 Next.js,约定优于配置。Node ≥ 20、pnpm 推荐。