跳至主要內容

概覽

本參考文件說明如何使用現有的 Mastra template,以及如何建立自己的 template,也涵蓋如何向社群生態系貢獻 template。

Mastra template 是預先建置的專案結構,用來示範特定使用案例與模式。它們提供:

  • 可運作的範例:完整且功能齊全的 Mastra 應用程式
  • 最佳實務:適當的專案結構與程式設計慣例
  • 學習資源:透過實際實作學習 Mastra 模式
  • 快速開始:比從零開始建置更快地建立專案

可用的 template
「可用的 template」的直接連結

下列 template 示範以 Gateway 為優先的 Mastra 應用程式:

  • template-docs-expert:透過 Gateway 網頁搜尋、引用、Memory 與結構化回應,回答文件相關問題。
  • template-browser-agent:使用 AgentBrowser 瀏覽、檢查網頁並與網頁互動。
  • template-meeting-notes:將 Zoom 逐字稿或上傳的逐字稿轉換成結構化筆記,其中包含決策與待辦事項。
  • template-company-knowledge:將 Linear 與 Notion 內容建立索引並存入 pgvector,再回答內部知識相關問題。
  • template-claw-assistant:透過檔案系統、Sandbox、瀏覽器與網頁搜尋 Tool 操作 Workspace。

使用 template
「使用 template」的直接連結

安裝
「安裝」的直接連結

使用 create-mastra 指令安裝 template:

npx create-mastra@latest my-project --template template-name

這會建立完整的專案並安裝其相依套件。template 作者會決定模型、Provider 相依套件、環境變數與原始碼。

設定流程
「設定流程」的直接連結

安裝完成後:

  1. 前往專案目錄

    cd your-project-name
  2. 設定環境變數

    cp .env.example .env

    依照 template README 的說明,編輯 .env 並填入所需的 API 金鑰。

  3. 啟動開發伺服器

    npm run dev

Template 結構
「Template 結構」的直接連結

所有 template 都採用下列標準化結構:

your-template/
├── src/
│ └── mastra/
│ ├── agents/ # Agent definitions
│ ├── tools/ # Tool definitions
│ ├── workflows/ # Workflow definitions
│ └── index.ts # Main Mastra config
├── .env.example # Required environment variables
├── package.json
├── tsconfig.json
└── README.md