mastra-ai/mastra
GitHub: mastra-ai/mastra
基于 TypeScript 的 AI 应用与 agent 开发框架,提供模型路由、工作流编排、上下文管理和可观测性等完整能力,帮助开发者快速构建生产级 AI 产品。
Stars: 25190 | Forks: 2252
# Mastra
[](https://www.npmjs.com/package/@mastra/core)
[](https://github.com/mastra-ai/mastra/actions/workflows/github-code-scanning/codeql)
[](https://github.com/mastra-ai/mastra/stargazers)
[](https://discord.gg/BTYqqHKUrf)
[](https://x.com/mastra)
[](https://www.npmjs.com/package/@mastra/core)
[](https://www.ycombinator.com/companies?batch=W25)
Mastra 是一个使用现代 TypeScript 技术栈构建 AI 驱动的应用程序和 agent 的框架。
它包含了将早期原型转化为生产级应用所需的一切。Mastra 可以与 React、Next.js 和 Node 等前端和后端框架集成,或者你也可以将其作为独立服务器部署到任何地方。这是构建、调优和扩展可靠的 AI 产品最简单的方式。
## 为什么选择 Mastra?
Mastra 专为 TypeScript 打造,并围绕成熟的 AI 模式设计,为你提供了开箱即用构建出色 AI 应用所需的一切。
部分亮点包括:
- [**模型路由**](https://mastra.ai/models) - 通过一个标准接口连接到 40 多家提供商。使用来自 OpenAI、Anthropic、Gemini 等的模型。
- [**Agent**](https://mastra.ai/docs/agents/overview) - 构建使用 LLM 和工具来解决开放式任务的自主 agent。Agent 能够推理目标、决定使用哪些工具,并进行内部迭代,直到模型输出最终答案或满足可选的停止条件。
- [**工作流**](https://mastra.ai/docs/workflows/overview) - 当你需要对执行进行显式控制时,可以使用 Mastra 基于图的工作流引擎来编排复杂的多步骤过程。Mastra 工作流使用直观的语法进行控制流(`.then()`、`.branch()`、`.parallel()`)。
- [**Human-in-the-loop**](https://mastra.ai/docs/workflows/suspend-and-resume) - 挂起 agent 或工作流,并在恢复之前等待用户输入或批准。Mastra 使用[存储](https://mastra.ai/docs/server-db/storage)来记忆执行状态,因此你可以无限期暂停,并从上次中断的地方继续。
- **上下文管理** - 在正确的时间为你的 agent 提供正确的上下文。提供[对话历史](https://mastra.ai/docs/memory/conversation-history),从你的来源(API、数据库、文件)中[检索](https://mastra.ai/docs/rag/overview)数据,并通过[观察记忆](https://mastra.ai/docs/memory/observational-memory)添加类人记忆,让你的 agent 表现得更加连贯。
- **集成** - 将 agent 和工作流打包到现有的 React、Next.js 或 Node.js 应用中,或者将其作为独立的 endpoint 发布。在构建 UI 时,可以与 Vercel 的 AI SDK UI 和 CopilotKit 等 agent 库集成,让你的 AI 助手在网络中生动呈现。
- [**MCP 服务器**](https://mastra.ai/docs/tools-mcp/mcp-overview) - 编写 Model Context Protocol 服务器,通过 MCP 接口暴露 agent、工具和其他结构化资源。然后,任何支持该协议的系统或 agent 都可以访问它们。
- **生产级要素** - 发布可靠的 agent 需要持续的洞察、评估和迭代。借助内置的[评估](https://mastra.ai/docs/evals/overview)和[可观测性](https://mastra.ai/docs/observability/overview),Mastra 为你提供了持续观察、衡量和改进的工具。
## 开始使用
开始使用 Mastra 的**推荐**方式是运行以下命令:
```
npm create mastra@latest
```
按照[安装指南](https://mastra.ai/docs/getting-started/installation)使用 CLI 进行逐步设置或手动安装。
如果你是 AI agent 的新手,请查看我们的[模板](https://mastra.ai/docs/getting-started/templates)、[课程](https://mastra.ai/course)和 [YouTube 视频](https://youtube.com/@mastra-ai),从今天就开始使用 Mastra 进行构建。
--default --llm
After project created, go to project dir. Start dev server: npx bgproc start -n -w -- npm run dev
Start Mastra Studio at http://localhost:4111. Studio = UI for build, test, manage agents, workflows, tools.
Also tell: Mastra model router give 3000+ models from many providers: https://mastra.ai/models
```
## 文档
访问我们的[官方文档](https://mastra.ai/docs)。
## 与 AI 共同构建
按照[与 AI 共同构建指南](https://mastra.ai/docs/getting-started/build-with-ai),了解如何让你的 agent 成为 Mastra 专家。
## 许可协议
本仓库采用双重许可模式:
- **Apache License 2.0** — 核心框架和本代码库的绝大多数内容均在 Apache-2.0 下开源。
- **Mastra 企业版许可** — 任何名为 `ee/` 的目录(例如 `packages/core/src/auth/ee/`)中的代码均在 Mastra 企业版许可下提供源码。这些功能在生产环境中使用需要有效的企业版许可,但可自由用于开发和测试。
有关完整的许可映射,请参阅 [LICENSE.md](./LICENSE.md);有关企业版许可条款,请参阅 [ee/LICENSE](./ee/LICENSE)。
## 安全性
我们致力于维护本仓库及整个 Mastra 的安全性。如果你发现了安全漏洞,我们恳请你通过 [security@mastra.ai](mailto:security@mastra.ai) 向我们负责任地披露,我们会与你联系。
替代方案:使用此预构建的 prompt 开始使用
``` Make new Mastra project. Mastra = framework for AI apps + agents on modern TypeScript stack. Before run command, ask these questions one by one. Wait for answers unless already given: Project name? (default: "my-mastra-app") Provider? (default: "openai", options: "openai", "anthropic", "groq", "google", "cerebras", "mistral") Provider rules: Allowed provider -> use it. Any other value -> use "openai". Run with answers: npm create mastra@latest标签:AI智能体, AI框架, DLL 劫持, MITM代理, TypeScript, 人工智能, 大语言模型, 安全插件, 工作流引擎, 暗色界面, 用户模式Hook绕过, 自动化攻击