字
字节笔记本
2026年2月23日
在 VS Code 中使用 Agent Skills - 官方文档
Agent Skills 是 GitHub Copilot 的开放标准扩展机制,通过 SKILL.md 文件定义可复用的专业能力与工作流。与仅含指令的自定义说明不同,技能可包含脚本、示例等资源,支持跨 VS Code、Copilot CLI 及编码代理使用。本文详细介绍 VS Code 中 Agent Skills 的使用方法、创建流程和最佳实践。
Agent Skills 与自定义指令的区别
虽然两者都能自定义 Copilot 行为,但用途不同:
| 特性 | Agent Skills | 自定义指令 |
|---|---|---|
| 用途 | 教授专业能力和工作流 | 定义编码标准和规范 |
| 可移植性 | 跨 VS Code、Copilot CLI、编码代理 | 仅 VS Code 和 GitHub.com |
| 内容 | 指令、脚本、示例、资源 | 仅指令 |
| 范围 | 任务特定,按需加载 | 始终应用(或通过 glob 模式) |
| 标准 | 开放标准 (agentskills.io) | VS Code 特定 |
使用 Agent Skills 的场景:
- 创建可跨不同 AI 工具复用的能力
- 包含脚本、示例或其他资源
- 与更广泛的 AI 社区共享能力
- 定义专业工作流(测试、调试、部署)
使用自定义指令的场景:
- 定义项目特定的编码标准
- 设置语言或框架约定
- 指定代码审查或提交消息规范
- 使用 glob 模式基于文件类型应用规则
创建 Skill
提示:在聊天输入中输入
/skills可快速打开配置 Skills菜单。
Skills 存储在包含 SKILL.md 文件的目录中。VS Code 支持两种类型的 skills:
| Skill 类型 | 位置 |
|---|---|
| 项目 skills | .github/skills/、.claude/skills/、.agents/skills/ |
| 个人 skills | ~/.copilot/skills/、~/.claude/skills/、~/.agents/skills/ |
提示:可通过
chat.agentSkillsLocations设置配置额外的搜索位置。
创建步骤
- 在工作区中创建
.github/skills目录 - 为 skill 创建子目录(如
.github/skills/webapp-testing) - 在 skill 目录中创建
SKILL.md文件 - 可选:添加脚本、示例或其他资源
SKILL.md 文件格式
SKILL.md 是带有 YAML frontmatter 的 Markdown 文件,定义 skill 的元数据和行为。
必需头部字段:
| 字段 | 必需 | 说明 |
|---|---|---|
name | 是 | 唯一标识符,小写,用连字符分隔,必须与目录名匹配 |
description | 是 | Skill 的功能描述和使用时机,最多 1024 字符 |
argument-hint | 否 | 斜杠命令调用时显示的提示文本 |
user-invokable | 否 | 是否显示在 / 菜单中,默认 true |
disable-model-invocation | 否 | 是否禁用自动加载,默认 false |
示例 SKILL.md:
yaml
---
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
```bash
npx playwright testTo debug tests:
bash
npx playwright test --debugtext
## 使用 Skills 作为斜杠命令
Skills 在聊天中作为斜杠命令可用。输入 `/` 查看可用 skills 和 prompts 列表。
可以添加额外上下文,例如:
- `/webapp-testing for the login page`
- `/github-actions-debugging PR #42`
通过 `user-invokable` 和 `disable-model-invocation` 属性控制访问方式:
| 配置 | 斜杠命令 | Copilot 自动加载 | 使用场景 |
|------|---------|-----------------|---------|
| 默认(省略两者) | 是 | 是 | 通用 skills |
| `user-invokable: false` | 否 | 是 | 背景知识 skills |
| `disable-model-invocation: true` | 是 | 否 | 仅按需运行 |
| 两者都设置 | 否 | 否 | 禁用 skills |
## Copilot 如何使用 Skills
Skills 使用渐进式披露机制,仅在需要时加载内容,三级加载系统确保可安装多个 skills 而不消耗上下文:
**Level 1: Skill 发现**
Copilot 始终通过读取 YAML frontmatter 中的 `name` 和 `description` 了解可用 skills。这些元数据轻量,帮助 Copilot 决定哪些 skills 与请求相关。
**Level 2: 指令加载**
当请求匹配 skill 的描述时,Copilot 将 `SKILL.md` 文件主体加载到上下文中。也可通过 `/` 斜杠命令直接调用 skill。
**Level 3: 资源访问**
Copilot 仅在需要时访问 skill 目录中的其他文件(脚本、示例、文档)。这些资源直到 Copilot 引用它们时才会加载,保持上下文高效。
## 使用共享 Skills
可以使用他人创建的 skills 增强 Copilot 能力:
- [github/awesome-copilot](https://github.com/github/awesome-copilot) - 社区 skills 集合
- [anthropics/skills](https://github.com/anthropics/skills) - 参考 skills
**使用步骤:**
1. 浏览仓库中的可用 skills
2. 复制 skill 目录到 `.github/skills/` 文件夹
3. 根据需求审查和自定义 `SKILL.md`
4. 可选:修改或添加资源
> 提示:使用前务必审查共享 skills,确保符合需求和安全标准。
## 从扩展贡献 Skills
扩展可通过 `package.json` 中的 `chatSkills` 贡献点提供 skills:
```json
{
"contributes": {
"chatSkills": [
{
"path": "./skills/my-skill"
}
]
}
}目录结构要求:
text
extension-root/
└── skills/
└── my-skill/ # 目录名必须与 SKILL.md 中的 `name` 匹配
└── SKILL.md # 必需重要:
SKILL.mdfrontmatter 中的name字段必须与父目录名匹配。
Agent Skills 标准
Agent Skills 是开放标准,支持跨不同 AI 代理的可移植性:
- VS Code 中的 GitHub Copilot:在聊天和代理模式中可用
- GitHub Copilot CLI:终端工作时可访问
- GitHub Copilot 编码代理:自动化编码任务期间使用
了解更多:agentskills.io
相关资源
分享: