> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # `createSkill()` 建立 inline Skill,不需要檔案系統或 Workspace,即可直接傳入 Agent 的 `skills` 設定。 回傳的物件會實作 `Skill` 介面,可用於任何支援檔案系統探索 Skill 的位置。 ## 使用範例 ```typescript import { createSkill } from '@mastra/core/skills' const reviewSkill = createSkill({ name: 'code-review', description: 'Use when reviewing code changes.', instructions: ` When reviewing code: 1. Check for correctness 2. Check for style consistency 3. Look for potential bugs `, references: { 'checklist.md': '# Review Checklist\n- No unused imports\n- Error handling present', }, }) ``` ## 參數 **name** (`string`): 唯一的 Skill 名稱。Agent 啟用 Skill 時會以此作為識別碼。必須是有效的 slug(可使用小寫字母與連字號)。 **description** (`string`): 在 system message 中向 Agent 顯示的簡短說明,用來協助 Agent 判斷何時使用此 Skill。 **instructions** (`string`): 以 Markdown 撰寫的完整 Skill 指示。Agent 啟用 Skill 時,這些指示會載入對話。 **references** (`Record`): Agent 可透過 skill\_read Tool 讀取的支援文件。key 是檔名,value 是檔案內容。 **license** (`string`): Skill 的 SPDX 授權識別碼。 **compatibility** (`unknown`): 相容性需求。Agent Skills 規格允許彈性定義此值,可以是字串陣列、物件,或您的工具預期的任何結構。 **user-invocable** (`boolean`): 終端使用者是否可以直接叫用此 Skill。預設為 undefined(由 Agent 決定)。 **metadata** (`Record`): 附加至 Skill 的任意 metadata。 ## 回傳值 回傳實作 `Skill` 介面的 `InlineSkill` 物件: ```typescript interface InlineSkill extends Skill { __inline: true __referenceContents: Record } ``` 此 Skill 會被指派 `inline/` 格式的合成路徑(例如 `inline/code-review`)。 ## 驗證 `createSkill()` 會使用與檔案系統 Skill 相同的規則驗證輸入: - `name` 為必填,且必須是有效的 slug - `description` 為必填 - `instructions` 為必填,且不得為空 驗證失敗時,會擲回 `Error`,並提供無效欄位的詳細資訊。 ```typescript // Throws: Invalid skill "": name is required createSkill({ name: '', description: 'test', instructions: 'test' }) ``` ## 相關內容 - [Agent Skill](https://mastra.zisheng.pro/zh-TW/docs/agents/skills) - [Workspace Skill](https://mastra.zisheng.pro/zh-TW/docs/workspace/skills) - [`.getSkill()` 參考文件](https://mastra.zisheng.pro/zh-TW/reference/agents/getSkill) - [`.listSkills()` 參考文件](https://mastra.zisheng.pro/zh-TW/reference/agents/listSkills)