Mastra 快速入门
🌐 Mastra Quickstart
create mastra CLI 命令是入门最快的方法。它会引导你完成设置,并为你创建示例代理、工作流程和工具,方便你在本地运行或进行修改。
🌐 The create mastra CLI command is the quickest way to get started. It walks you through setup and creates example agents, workflows, and tools for you to run locally or adapt.
如果你需要对设置有更多控制,请参阅手动安装指南。你也可以在现有项目中使用mastra init。
🌐 If you need more control over the setup, see the manual installation guide. You can also use mastra init for existing projects.
在你开始之前Direct link to 在你开始之前
🌐 Before you begin
初始化 MastraDirect link to 初始化 Mastra
🌐 Initialize Mastra
你可以在你的计算机上的任何地方运行 create mastra。
🌐 You can run create mastra anywhere on your machine.
在提示时,选择一个提供商(例如 OpenAI)并输入你的密钥:
🌐 When prompted, choose a provider (e.g. OpenAI) and enter your key:
- npm
- pnpm
- Yarn
- Bun
npm create mastra@latest
pnpm create mastra
yarn create mastra
bunx create-mastra
这会为你的项目创建一个新目录,其中包含一个 src/mastra 文件夹,里面有一个示例天气代理和以下文件:
🌐 This creates a new directory for your project with a src/mastra folder containing an example weather agent and the following files:
index.ts- Mastra 配置,包括内存tools/weather-tool.ts- 一个用于获取给定位置天气的工具agents/weather-agent.ts- 一个使用该工具的天气代理及其提示
测试你的代理Direct link to 测试你的代理
🌐 Test your agent
设置完成后,请按照终端中的指示启动 Mastra 开发服务器,然后在 localhost:4111 打开 Studio。
🌐 Once setup is complete, follow the instructions in your terminal to start the Mastra dev server, then open Studio at localhost:4111.
试着询问天气。如果你的 API 密钥设置正确,你将收到一个回应:
🌐 Try asking about the weather. If your API key is set up correctly, you'll get a response:
Studio 让你可以快速构建和原型化代理,无需创建用户界面。一旦准备就绪,你可以使用下面的指南将你的 Mastra 代理集成到应用中。
下一步Direct link to 下一步
🌐 Next steps
- 将 Mastra 集成到你的前端框架中:Next.js、React 或 Astro
- 阅读更多关于Mastra 的功能
- 按照我们的指南从头构建一个代理
- 在我们的YouTube 通道观看概念指南并订阅