在 VS Code 中使用代理技能

代理技能是指令、指令碼和資源的資料夾,GitHub Copilot 可以在相關時載入這些資料夾以執行專業化任務。代理技能是 開放標準,適用於多個 AI 代理程式,包括 VS Code 中的 GitHub Copilot、GitHub Copilot CLI 和 GitHub Copilot 程式碼撰寫代理程式。

與主要定義程式碼撰寫指南的自訂指示不同,技能可啟用專業化功能和工作流程,其中可包含指令碼、範例和其他資源。您建立的技能具有可攜性,並適用於任何與技能相容的代理程式。

代理技能的主要優點

  • 專業化 Copilot:針對特定領域任務量身打造功能,無需重複上下文
  • 減少重複:建立一次,在所有對話中自動使用
  • 組合功能:結合多個技能以建構複雜工作流程
  • 高效率載入:僅在需要時載入相關內容至上下文
提示

使用 聊天自訂編輯器 (預覽版) 在一處探索、建立和管理所有聊天自訂。從命令選擇區執行 聊天:開啟聊天自訂

代理技能與自訂指示

雖然代理技能和自訂指示都有助於自訂 Copilot 的行為,但它們的用途不同

功能 代理程式技能 自訂指示
目的 教導專業化功能和工作流程 定義程式碼標準和指南
可攜性 適用於 VS Code、Copilot CLI 和 Copilot 程式碼撰寫代理程式 僅限 VS Code 和 GitHub.com
內容 指示、指令碼、範例和資源 僅指示
範圍 針對特定任務,隨需載入 永遠套用 (或透過 glob 模式)
標準 開放標準 (agentskills.io) VS Code 特有

當您想要執行下列操作時,請使用代理技能

  • 建立適用於不同 AI 工具的可重複使用功能
  • 將指令碼、範例或其他資源與指示一併納入
  • 與更廣泛的 AI 社群共用功能
  • 定義專業化工作流程,例如測試、偵錯或部署程序

當您想要執行下列操作時,請使用自訂指示

  • 定義專案專屬的程式碼標準
  • 設定語言或框架慣例
  • 指定程式碼審查或提交訊息指南
  • 使用 glob 模式根據檔案類型套用規則

建立技能

提示

在聊天輸入中輸入 /skills 可快速開啟設定技能選單。

技能儲存在具有 SKILL.md 檔案的目錄中,此檔案定義了技能的行為。VS Code 支援兩種技能類型

技能類型 位置
專案技能,儲存在您的儲存庫中 .github/skills/.claude/skills/.agents/skills/
個人技能,儲存在您的使用者設定檔中 ~/.copilot/skills/~/.claude/skills/~/.agents/skills/

您可以使用 chat.skillsLocations 在 VS Code 中開啟 在 VS Code Insiders 中開啟 設定來設定專案技能的其他檔案位置。如果您想要以不同的資料夾結構組織技能或擁有多個技能目錄,這會很有用。

提示

在單一儲存庫 (monorepo) 中,啟用 chat.useCustomizationsInParentRepositories 在 VS Code 中開啟 在 VS Code Insiders 中開啟 以從父儲存庫根目錄中探索技能。深入了解 父儲存庫探索

建立技能

  1. 在「聊天」檢視中,選取設定聊天 (齒輪圖示) 以開啟「聊天自訂」編輯器,然後選取技能索引標籤。

  2. 從下拉式選單中選取新增技能 (工作區)新增技能 (使用者),視您要儲存技能的位置而定。

    Screenshot of the Chat Customizations editor, showing the Skills tab and the dropdown to create a new skill.

  3. 選取位置並輸入技能名稱。

  4. 填寫 YAML frontmatter 並在檔案主體中新增指示,以完成 SKILL.md 檔案。

    ---
    name: skill-name
    description: Description of what the skill does and when to use it
    ---
    
    # Skill Instructions
    
    Your detailed instructions, guidelines, and examples go here...
    
  5. 您可以選擇將指令碼、範例或其他資源新增至技能目錄。

    例如,用於測試 Web 應用程式的技能可能包含

    • SKILL.md - 執行測試的指示
    • test-template.js - 範本測試檔案
    • examples/ - 範例測試情境
    注意

    請確保在您的 SKILL.md 中引用任何其他檔案,以便代理程式能找到它們。使用具有相對路徑的 Markdown 連結語法,例如 [test template](./test-template.js)

使用 AI 生成技能

您可以根據功能的描述使用 AI 生成技能。在聊天中輸入 /create-skill 並描述您想要的技能 (例如,「用於執行和偵錯整合測試的技能」)。代理程式會提出澄清問題,並生成包含目錄結構、指示和 frontmatter 的 SKILL.md 檔案。

您也可以從進行中的對話中提取可重複使用的技能。例如,在您偵錯複雜問題的多輪對話之後,詢問「從我們剛才偵錯的方式建立技能」以將多步驟程序擷取為可重複使用的技能。

您也可以從「聊天自訂」編輯器中,從下拉式選單中選取生成技能來生成技能。

SKILL.md 檔案格式

SKILL.md 檔案是包含 YAML frontmatter 的 Markdown 檔案,用於定義技能的中繼資料和行為。

標頭 (必要)

標頭的格式為 YAML frontmatter,包含以下欄位

欄位 必填 說明
name 技能的唯一識別碼。必須是小寫,使用連字號分隔單字 (例如,webapp-testing)。必須與父目錄名稱相符。最多 64 個字元。
description 描述技能的功能以及何時使用。具體說明功能和使用案例,以幫助 Copilot 決定何時載入技能。最多 1024 個字元。
argument-hint 當技能做為斜線命令叫用時,在聊天輸入欄位中顯示的提示文字。幫助使用者了解要提供哪些額外資訊 (例如,[test file] [options])。
user-invocable 控制技能是否顯示為聊天選單中的斜線命令。預設為 true。設定為 false 可從 / 選單隱藏技能,但仍允許代理程式自動載入它。
disable-model-invocation 控制代理程式是否能根據相關性自動載入技能。預設為 false。設定為 true 僅限透過 / 斜線命令手動叫用。

主體

技能主體包含 Copilot 在使用此技能時應遵循的指示、指南和範例。撰寫清晰、具體的指示,描述

  • 技能有助於完成什麼
  • 何時使用技能
  • 要遵循的逐步程序
  • 預期的輸入和輸出的範例
  • 任何包含的指令碼或資源的參考

您可以使用相對路徑參考技能目錄中的檔案。例如,若要參考技能目錄中的指令碼,請使用 [test script](./test-template.js)

範例技能

以下範例示範您可以建立的不同類型技能。

範例:Web 應用程式測試技能
---
name: webapp-testing
description: Guide for testing web applications using Playwright. Use this when asked to create or run browser-based tests.
---

# Web Application Testing with Playwright

This skill helps you create and run browser-based tests for web applications using Playwright.

## When to use this skill

Use this skill when you need to:
- Create new Playwright tests for web applications
- Debug failing browser tests
- Set up test infrastructure for a new project

## Creating tests

1. Review the [test template](./test-template.js) for the standard test structure
2. Identify the user flow to test
3. Create a new test file in the `tests/` directory
4. Use Playwright's locators to find elements (prefer role-based selectors)
5. Add assertions to verify expected behavior

## Running tests

To run tests locally:
```bash
npx playwright test
```

To debug tests:
```bash
npx playwright test --debug
```

## Best practices

- Use data-testid attributes for dynamic content
- Keep tests independent and atomic
- Use Page Object Model for complex pages
- Take screenshots on failure
範例:GitHub Actions 偵錯技能
---
name: github-actions-debugging
description: Guide for debugging failing GitHub Actions workflows. Use this when asked to debug failing GitHub Actions workflows.
---

# GitHub Actions Debugging

This skill helps you debug failing GitHub Actions workflows in pull requests.

## Process

1. Use the `list_workflow_runs` tool to look up recent workflow runs for the pull request and their status
2. Use the `summarize_job_log_failures` tool to get an AI summary of the logs for failed jobs
3. If you need more information, use the `get_job_logs` or `get_workflow_run_logs` tool to get the full failure logs
4. Try to reproduce the failure locally in your environment
5. Fix the failing build and verify the fix before committing changes

## Common issues

- **Missing environment variables**: Check that all required secrets are configured
- **Version mismatches**: Verify action versions and dependencies are compatible
- **Permission issues**: Ensure the workflow has the necessary permissions
- **Timeout issues**: Consider splitting long-running jobs or increasing timeout values

將技能做為斜線命令使用

技能與 提示檔案 一同做為斜線命令在聊天中提供。在聊天輸入欄位中輸入 /,即可查看可用技能和提示的清單,然後選取一個技能來叫用它。

您可以在斜線命令後新增額外上下文。例如,/webapp-testing for the login page/github-actions-debugging PR #42

依預設,所有技能都會顯示在 / 選單中。使用 user-invocabledisable-model-invocation frontmatter 屬性來控制每個技能的存取方式

設定 斜線指令 由 Copilot 自動載入 使用案例
預設 (兩個屬性皆省略) 一般用途技能
user-invocable: false 模型在相關時載入的背景知識技能
disable-model-invocation: true 您只想隨需執行的技能
兩者皆設定 已停用技能

Copilot 如何使用技能

技能會逐步載入內容,以保持您的上下文高效。以下是 Copilot 如何使用 webapp-testing 技能的範例

  1. 探索:Copilot 從 YAML frontmatter 讀取技能的 namedescription。當您詢問「協助我測試登入頁面」時,Copilot 會根據其描述將其與 webapp-testing 技能配對。

  2. 指示載入:Copilot 會將 SKILL.md 主體載入其上下文,使其能夠存取詳細的測試程序和指南。您也可以透過在聊天中輸入 /webapp-testing 直接觸發此步驟。

  3. 資源存取:當 Copilot 執行指示時,它僅在引用技能目錄中的其他檔案 (例如 test-template.js 或範例情境) 時才會存取它們。如果檔案未在指示中引用,則不會載入。

這種三層式載入系統表示您可以安裝許多技能而不會消耗上下文。Copilot 僅載入每個任務相關的內容。

使用共用技能

您可以使用他人建立的技能來增強 Copilot 的功能。github/awesome-copilot 儲存庫包含不斷增長的社群技能、自訂代理程式、指示和提示集合。anthropics/skills 儲存庫包含其他參考技能。

您也可以探索並安裝代理程式外掛程式中捆綁的技能。已安裝外掛程式中的技能會與您在設定技能選單中本機定義的技能一併顯示。

使用共用技能

  1. 瀏覽儲存庫中可用的技能
  2. 將技能目錄複製到您的 .github/skills/ 資料夾
  3. 檢閱並依需求自訂 SKILL.md 檔案
  4. 視需要選擇性修改或新增資源
提示

在使用共用技能之前,務必先檢閱它們,以確保它們符合您的需求和安全性標準。VS Code 的終端機工具提供了指令碼執行的控制項,包括具有可設定允許清單和嚴格控制哪些程式碼執行的自動核准選項。深入了解自動核准功能的安全性考量

透過擴充功能貢獻技能

擴充功能可以使用其 package.json 中的 chatSkills 貢獻點來貢獻技能。路徑必須指向包含 SKILL.md 檔案的目錄,並遵循 代理技能規格

必要資料夾結構

技能目錄必須遵循此結構

extension-root/
└── skills/
    └── my-skill/           # Directory name must match the `name` field in SKILL.md
        └── SKILL.md         # Required

在 package.json 中註冊技能

在擴充功能的 package.json 中新增 chatSkills 貢獻點。path 屬性必須指向對應的 SKILL.md 檔案

{
  "contributes": {
    "chatSkills": [
      {
        "path": "./skills/my-skill/SKILL.md"
      }
    ]
  }
}
重要

SKILL.md frontmatter 中的 name 欄位必須與父目錄名稱相符。例如,如果目錄是 skills/my-skill/,則 name 欄位必須是 my-skill。如果名稱不相符,則不會載入技能。

SKILL.md 檔案遵循與專案和個人技能相同的格式。例如

---
name: my-skill
description: Description of what the skill does and when to use it.
---

# My Skill

Detailed instructions for the skill...

代理技能標準

代理技能是一個開放標準,可在不同的 AI 代理程式之間實現可攜性。您在 VS Code 中建立的技能可與多個代理程式搭配使用,包括

  • VS Code 中的 GitHub Copilot:適用於聊天和代理程式模式
  • GitHub Copilot CLI:在終端機中工作時可存取
  • GitHub Copilot 程式碼撰寫代理程式:在自動化程式碼撰寫任務期間使用

agentskills.io 進一步了解代理技能標準。

© . This site is unofficial and not affiliated with Microsoft.