Mastra Quickstart
create-mastra CLI 是启动 Mastra 项目的最快方式。它会创建一个 Agent Harness,其中包含 Workspace Tool、Memory、任务跟踪、Web 访问、Schedule、Storage 和 Observability。
如需更多控制,请参阅手动安装指南。如需将 Mastra 添加到现有项目,请使用 mastra init。
Create a new Mastra project. Mastra is a framework for AI applications and agents on a modern TypeScript stack. Before running the command, ask these questions one at a time and wait for each answer unless it was already provided:
- Project name? (default: "my-mastra-app")
- Provider? (required; options: "openai", "anthropic", "google", "xai")
If the provider isn't supported, ask again and list the supported values.
Run: npm create mastra@latest <project-name> -- --llm <provider>
The command creates a default Mastra project, installs Mastra skills for detected coding assistants, and initializes Git when appropriate.
After creation, enter the project directory and start the dev server: npx bgproc start -n <project-name> -w -- npm run dev
Open Mastra Studio at http://localhost:4111. Studio is the interface for building, testing, and managing agents, workflows, and tools.
Also mention that the Mastra model router provides access to thousands of models: https://mastra.ai/models
观看 Mastra AI Agent 课程,跟随引导了解如何使用 Mastra 构建 Agent。
开始之前开始之前的直接链接
你需要 OpenAI、Anthropic、Google Gemini 或 xAI 的 API Key。设置过程中可以暂时跳过,稍后再将其添加到 .env。
创建项目创建项目的直接链接
运行交互式设置:
- npm
- pnpm
- Yarn
- Bun
npm create mastra@latest
pnpm create mastra@latest
yarn create mastra
bunx create-mastra
该命令会询问项目名称、模型 Provider 和可选的 API Key。随后,它会安装依赖、为你的 coding assistant 安装 Mastra Skill;如果当前不在已有仓库中,还会创建初始 Git commit。
生成的 src/mastra 目录包含 Mastra 入口、Agent、Workspace Tool 和配套代码。标准 Mastra 目录布局请参阅项目结构 Reference。
使用 --template <template> 从模板开始,或使用 --empty 创建不含 Provider 的最小项目。使用 --no-skills 或 --no-git 可跳过自动设置。所有参数请参阅 create-mastra Reference。
测试你的 Agent测试你的 Agent的直接链接
按照终端提示进入项目目录并启动开发 Server:
- npm
- pnpm
- Yarn
- Bun
npm run dev
pnpm run dev
yarn dev
bun run dev
打开 localhost:4111 上的 Studio,选择 Agent 并发送消息。如果设置时跳过了 API Key,请将 .env.example 中指定的 Provider API Key 添加到 .env 文件。
Studio 让你无需单独创建 UI,就能构建和测试 Agent。
后续步骤后续步骤的直接链接
- 将 Mastra 与 Next.js、React 或 Astro 集成
- 了解如何使用 AI 构建 Mastra
- 跟随指南从零构建 Agent
- 观看 Mastra YouTube 频道