mastra

From the team behind Gatsby, Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

22.5k
Stars
+870
Stars/month
10
Releases (6m)

Star Growth

+155 (0.7%)
21.9k22.5k23.0kMar 27Apr 1

Overview

Mastra 是由 Gatsby 团队开发的 TypeScript AI 应用构建框架,专为快速构建从原型到生产级别的 AI 应用而设计。该框架通过统一接口连接超过 40 个 AI 提供商(包括 OpenAI、Anthropic、Gemini 等),提供模型路由、自主代理、工作流编排等核心功能。Mastra 支持与 React、Next.js、Node.js 等主流前后端框架集成,也可作为独立服务器部署。其核心优势在于提供了完整的 AI 应用开发工具链,包括智能代理构建、基于图的工作流引擎、人机交互循环支持,以及强大的上下文管理系统。框架采用现代 TypeScript 技术栈,遵循成熟的 AI 开发模式,为开发者提供了构建可靠 AI 产品的完整解决方案。目前在 GitHub 上拥有超过 22,000 个星标,显示了其在开发社区中的受欢迎程度。

Deep Analysis

Key Differentiator

Unlike LangChain (Python-first, complex abstraction) or CrewAI (Python multi-agent), Mastra is purpose-built for TypeScript with native Next.js/React integration, graph-based workflows with .then()/.branch()/.parallel() syntax, and built-in evals — making it the most natural choice for JS/TS production agent development.

Capabilities

  • TypeScript-first AI agent framework with model routing across 40+ providers through one interface
  • Graph-based workflow engine with intuitive .then()/.branch()/.parallel() syntax
  • Human-in-the-loop suspend/resume for agent and workflow approval workflows
  • Conversation history, working memory, and semantic recall for context management
  • Built-in evals and OpenTelemetry-based observability for production monitoring
  • MCP server authoring to expose agents and tools via Model Context Protocol
  • Integrates with React, Next.js, Vercel AI SDK, and CopilotKit for frontend UIs

🔗 Integrations

OpenAIAnthropicGoogle GeminiVercel AI SDKReactNext.jsCopilotKitMCP

Best For

  • TypeScript/Node.js teams building production AI agents with React/Next.js frontends
  • Developers who want agent workflows with human-in-the-loop approval built into their existing JS stack

Not Ideal For

  • Python-first data science teams — use LangChain or PydanticAI instead
  • Simple chatbot UIs without agent logic — use Vercel AI SDK directly

Languages

TypeScriptJavaScript

Deployment

npm packageStandalone serverNext.js integrationNode.js backend

Pricing Detail

Free: Open-source under Apache 2.0 (enterprise features under separate license)
Paid: Enterprise license for ee/ directory features

Known Limitations

  • TypeScript-only — no Python SDK for data science workflows
  • Relatively new framework (YC W25) — ecosystem still growing
  • Enterprise features (auth in ee/ directory) require separate license
  • Less battle-tested than LangChain for complex RAG pipelines

Pros

  • + 统一的多提供商接口支持 40+ AI 模型提供商,避免供应商锁定
  • + 完整的 AI 应用工具链包括代理、工作流、人机交互和上下文管理
  • + TypeScript 原生支持和现代技术栈集成,开发体验优秀

Cons

  • - 作为相对较新的框架,生态系统和社区资源可能有限
  • - 多功能集成可能带来学习曲线,需要时间掌握各个组件
  • - 文档和最佳实践可能还在完善中,缺少大规模生产案例

Use Cases

  • 构建需要多个 AI 模型协作的复杂智能代理系统
  • 开发需要人机交互审批流程的自动化工作流应用
  • 快速原型验证 AI 产品概念并扩展到生产环境

Getting Started

1. 安装核心包:`npm install @mastra/core` 2. 配置 AI 提供商和基本设置,选择所需的模型提供商 3. 创建第一个代理或工作流,利用框架的模板和示例快速上手

Compare mastra