框架 · Mastra
快速了解 Mastra
一个 TypeScript framework,将 agents、支持暂停和恢复的 workflows、memory、evals 和 Studio UI 整合在同一个包中。可集成到 Next.js、Express 或 Hono 应用中;核心部分采用 Apache-2.0 许可证,ee/ 目录则采用企业许可证。
适用于: 希望用一套技术栈构建 agents、workflows、memory 和 evals 的 TypeScript 团队。
关键信息
- 维护者
- Mastra
- 语言
- TypeScript
- 许可证
- Apache-2.0 (core)
- 最新版本
@mastra/core 1.73.0· 2026年10月1日- 代码仓库
- mastra-ai/mastra
- 托管选项
- Mastra Cloud / Mastra Platform
快速入门
安装软件包、设置凭据,然后运行官方文档中的最简 agent。这里使用的模型 ID 与文档一致,但你的账户可能尚未启用这些模型。
npm install @mastra/core@latest zod@latest typescript@latest @types/node@latest mastra@latest (or scaffold: npm create mastra@latest)// src/mastra/agents/weather-agent.ts
import { Agent } from '@mastra/core/agent'
import { weatherTool } from '../tools/weather-tool.ts'
export const weatherAgent = new Agent({
id: 'weather-agent',
name: 'Weather Agent',
instructions: `
You are a helpful weather assistant that provides accurate weather information.
Your primary function is to help users get weather details for specific locations. When responding:
- Include relevant details like humidity, wind conditions, and precipitation
- Keep responses concise but informative
Use the weatherTool to fetch current weather data.
`,
// Use a string in provider/model format, not provider:model or a provider object.
model: 'openai/gpt-5.6-sol',
tools: { weatherTool },
})
// run.mjs (after registering the agent in src/mastra/index.ts)
import { mastra } from './src/mastra/index.ts'
const agent = mastra.getAgentById('weather-agent')
const response = await agent.generate('Weather in SF')
console.log(response.text)功能
| 支持任意模型 | 是 | 模型路由使用 provider/model 格式的字符串 |
|---|---|---|
| MCP 客户端 | 是 | |
| MCP 服务器 | 是 | MCPServer 可公开 agents、tools、workflows、prompts 和 resources |
| 多 agent | 是 | agent 可以作为其他 agent 的工具 |
| 持久化运行 | 是 | 通过 libSQL、Postgres 等存储快照,实现暂停和恢复 |
| 人工审批 | 是 | suspend() 和 resume() 用于收集人工输入 |
| 追踪 | 是 | 通过 OTel exporter 对接 Langfuse、Braintrust、Datadog 和 LangSmith |
| 评测 | 是 | Scorer 可通过采样在线运行,也可在 CI 中离线运行 |
近期更新
- npm create mastra 现在可搭建通用 harness,包含 workspace、shell 工具、memory 和定时任务。
- Mastra Factory 面向由 coding agents 构建的软件工厂。