Mastra 快速入門
create-mastra CLI 是開始建立 Mastra 項目最快捷的方式。它會建立 Agent Harness,當中包含 Workspace Tool、記憶體、任務追蹤、網絡存取、排程、儲存及可觀測性。
如需更多控制,請參閱手動安裝指南。如要將 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 金鑰。你可以在設定期間略過輸入,稍後再將金鑰加入 .env。
建立項目建立項目 的直接連結
執行互動式設定:
- npm
- pnpm
- Yarn
- Bun
npm create mastra@latest
pnpm create mastra@latest
yarn create mastra
bunx create-mastra
此命令會要求你輸入項目名稱、模型 Provider 及可選的 API 金鑰。然後,它會安裝依賴套件、為你的編程助手安裝 Mastra Skill;如你目前不在現有的程式庫內,亦會建立初始 Git commit。
所產生的 src/mastra 目錄包含 Mastra 進入點、Agent、Workspace Tool 及相關程式碼。標準 Mastra 目錄配置請參閱項目結構參考資料。
使用 --template <template> 從範本開始,或使用 --empty 建立不含 Provider 的最小項目。使用 --no-skills 或 --no-git 可略過自動設定。所有參數請參閱 create-mastra 參考資料。
測試你的 Agent測試你的 Agent 的直接連結
按照終端機指示進入項目目錄,然後啟動開發伺服器:
- npm
- pnpm
- Yarn
- Bun
npm run dev
pnpm run dev
yarn dev
bun run dev
開啟 localhost:4111 的 Studio,選擇 Agent 並傳送訊息。如在設定期間略過了 API 金鑰,請將 .env.example 中指定的 Provider API 金鑰加入 .env 檔案。
Studio 讓你無需另行建立 UI,即可建立及測試 Agent。
下一步下一步 的直接連結
- 將 Mastra 與 Next.js、React 或 Astro 整合
- 了解如何使用 AI 建立 Mastra
- 按照指南從頭建立 Agent
- 觀看 Mastra YouTube 頻道