注意
代理技能与Copilot编程助理、GitHub Copilot 命令行界面 (CLI)和Visual Studio Code中的代理模式一起工作。
代理技能是包含说明、脚本和资源的文件夹,当需要时,这些文件夹可以被加载,以提升其在专用任务中的性能。 有关详细信息,请参阅“关于代理技能”。
创建和添加技能
要创建代理技能,你需要编写一个SKILL.md文件,并可选择其他资源,例如补充的 Markdown 文件或脚本,这些资源可以在SKILL.md说明中引用。
若要添加技能,请将文件以及任何辅助资源保存到 SKILL.md 知道查找技能的位置 Copilot 。 这可以位于存储库中,也可以位于主目录中。
-
在一个受支持的位置中创建一个
skills目录,用于存储技能,以及将来可能需要创建的任何其他目录。对于特定于单个存储库的项目技能,请在存储库中创建和使用
.github/skills或.claude/skills``.agents/skills目录。对于个人技能,可以在项目中共享,并在主目录中创建和使用
~/.copilot/skills、~/.claude/skills或~/.agents/skills目录。 -
为新技能创建子目录。 每个技能都应有自己的目录(例如
.github/skills/webapp-testing)。技能子目录名称应为小写,对空格使用连字符。
-
在技能子目录中,创建包含
SKILL.md技能说明的文件。重要
技能文件必须命名
SKILL.md。`SKILL.md` 文件是带有 YAML frontmatter 的 Markdown 文件。 在最简单的形式中,它们包括:- YAML 前页 * 名称 (必需):技能的唯一标识符。 这必须是小写的,对空格使用连字符。 通常,这与技能目录的名称匹配。 * 说明 (必需):描述技能的作用,以及何时 Copilot 应使用它。 * 许可证 (可选):适用于此技能的许可证的说明。
- 针对 Copilot 的 Markdown 正文,其中包含需要遵循的说明、示例和指南。
-
(可选)将脚本、示例或其他资源添加到技能的目录中。
有关详细信息,请参阅“启用技能以运行脚本”。
示例 SKILL.md 文件
对于 项目技能,此文件将位于 .github/skills/github-actions-failure-debugging 存储库的目录中。
对于 个人技能,此文件将位于目录中 ~/.copilot/skills/github-actions-failure-debugging 。
--- name: github-actions-failure-debugging description: Guide for debugging failing GitHub Actions workflows. Use this when asked to debug failing GitHub Actions workflows. --- To debug failing GitHub Actions workflows in a pull request, follow this process, using tools provided from the GitHub MCP Server: 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, to understand what went wrong without filling your context windows with thousands of lines of logs 3. If you still need more information, use the `get_job_logs` or `get_workflow_run_logs` tool to get the full, detailed failure logs 4. Try to reproduce the failure yourself in your own environment. 5. Fix the failing build. If you were able to reproduce the failure yourself, make sure it is fixed before committing your changes.
---
name: github-actions-failure-debugging
description: Guide for debugging failing GitHub Actions workflows. Use this when asked to debug failing GitHub Actions workflows.
---
To debug failing GitHub Actions workflows in a pull request, follow this process, using tools provided from the GitHub MCP Server:
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, to understand what went wrong without filling your context windows with thousands of lines of logs
3. If you still need more information, use the `get_job_logs` or `get_workflow_run_logs` tool to get the full, detailed failure logs
4. Try to reproduce the failure yourself in your own environment.
5. Fix the failing build. If you were able to reproduce the failure yourself, make sure it is fixed before committing your changes.
使技能能够运行脚本
调用技能时, Copilot 会自动发现技能目录中的所有文件,并使其与技能的说明一起可用。 这意味着你可以在技能目录中包括脚本或其他资源,并在说明中 SKILL.md 引用它们。
创建运行脚本的技能:
-
**将脚本添加到技能的目录中。** 例如,将 SVG 图像转换为 PNG 的技能可能具有以下结构。.github/skills/image-convert/ ├── SKILL.md └── convert-svg-to-png.sh -
**(可选)预先批准技能所需的工具。** 在前言`SKILL.md`中,可以使用`allowed-tools`字段列出会用到的工具Copilot,而无需每次都要求确认。 如果 `allowed-tools` 字段中未列出某个工具,Copilot 在使用前会提示你授予权限。--- name: image-convert description: Converts SVG images to PNG format. Use when asked to convert SVG files. allowed-tools: shell ---警告
仅在你已查看此技能和所有引用的脚本,并完全信任它们的来源后,才预先批准
shell或bash工具。 预先批准shell或bash会移除运行终端命令的确认步骤,并可能允许攻击者控制的技能或提示注入在你的环境中执行任意命令。 在有疑虑时,请省略shell和bash自allowed-tools,这样 Copilot 必须在运行终端命令之前请求您明确的确认。 -
**编写说明,说明 Copilot 如何使用脚本。** 在 Markdown 正文 `SKILL.md`中,描述脚本的运行时间和方式。When asked to convert an SVG to PNG, run the `convert-svg-to-png.sh` script from this skill's base directory, passing the input SVG file path as the first argument.
如何使用 Copilot 的代理技能
执行任务时,Copilot 将根据您的提示和技能描述决定何时使用您的技能。
当 Copilot 选择使用某项技能时,SKILL.md 文件将注入智能体的上下文中,使智能体能够访问你的指令。 然后,它可以按照这些说明执行操作,并使用你在技能目录中包含的任何脚本或示例。
技能与自定义指令的对比
你可以同时使用技能和自定义指令,教 Copilot 如何在你的存储库中工作以及如何执行特定任务。
我们建议将自定义指令用作几乎与每个任务相关的简单指令(例如有关存储库编码标准的信息),将技能用于 Copilot 仅在相关时才应访问的更详细指令。
若要了解有关存储库自定义说明的详细信息,请参阅 为GitHub Copilot添加存储库自定义说明。