跳至主要內容

概覽

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

Mastra templates 是預先建構的項目結構,用以示範特定使用案例及模式。這些 templates 提供:

  • 可運行範例:完整且功能齊全的 Mastra 應用程式
  • 最佳實踐:合適的項目結構及編程慣例
  • 學習資源:透過實際實作學習 Mastra 模式
  • 快速入門:相比從零開始建構,能更快建立項目

可用 templates
可用 templates 的直接連結

以下 templates 示範以 Gateway 為先的 Mastra 應用程式:

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

使用 templates
使用 templates 的直接連結

安裝
安裝 的直接連結

使用 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 結構 的直接連結

所有 templates 均採用以下標準化結構:

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