在 VS Code 中使用智能体技能 (Agent Skills)

智能体技能 (Agent Skills) 是包含指令、脚本和资源的文件夹,当 GitHub Copilot 认为相关时,可以加载这些内容来执行专门的任务。智能体技能是一个开放标准,适用于多个 AI 智能体,包括 VS Code 中的 GitHub Copilot、GitHub Copilot CLI 和 GitHub Copilot 编码智能体。

与主要定义编码指南的自定义指令不同,技能可以实现专门的功能和工作流程,其中可包含脚本、示例和其他资源。您创建的技能具有可移植性,可在任何兼容该标准的智能体上使用。

智能体技能的主要优势

  • 专职化 Copilot:针对特定领域的任务定制功能,无需重复提供上下文。
  • 减少重复:一次创建,在所有对话中自动使用。
  • 组合功能:结合多种技能来构建复杂的工作流程。
  • 高效加载:仅在需要时将相关内容加载到上下文中。
提示

使用 聊天自定义编辑器(预览版)在一个地方发现、创建和管理所有聊天自定义项。从命令面板运行 Chat: Open Chat Customizations(聊天:打开聊天自定义项)。

智能体技能与自定义指令

虽然智能体技能和自定义指令都有助于自定义 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. 填写 SKILL.md 文件,填入 YAML 前端元数据 (frontmatter) 并在文件正文中添加指令。

    ---
    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 并描述您想要的技能(例如,“一个用于运行和调试集成测试的技能”)。智能体会提出澄清问题,并生成包含目录结构、指令和前端元数据的 SKILL.md 文件。

您还可以从正在进行的对话中提取可复用的技能。例如,在经历了一次调试复杂问题的多轮对话后,您可以询问“根据我们刚才调试的方法创建一个技能”,以将此多步过程捕获为可复用的技能。

您也可以在“聊天自定义”编辑器中,通过从下拉菜单选择生成技能来创建技能。

SKILL.md 文件格式

SKILL.md 是一个带有 YAML 前端元数据的 Markdown 文件,用于定义技能的元数据和行为。

Header(必需)

头部格式为 YAML frontmatter,包含以下字段

字段 必需 描述
name 技能的唯一标识符。必须为小写,使用连字符连接(例如 webapp-testing)。必须与父目录名称匹配。最多 64 个字符。
描述 描述该技能的作用以及何时使用它。在能力和用例上都要具体,以帮助 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 前端元数据属性来控制每个技能的访问方式:

配置 斜杠命令 由 Copilot 自动加载 用例
默认(两个属性均省略) 通用技能
user-invocable: false 模型在相关时加载的后台知识技能
disable-model-invocation: true 您只想按需运行的技能
两者均设置 已禁用的技能

Copilot 如何使用技能

技能会逐步加载内容,以保持上下文的高效性。以下是 Copilot 如何使用 webapp-testing 技能的示例:

  1. 发现:Copilot 从 YAML 前端元数据中读取技能的 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 前端元数据中的 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.