实操 01 · 英文原文 · 授权全文收录
官方 Skill 快速开始:掷骰子
完整收录官方现成例子:在 VS Code 创建 roll-dice 技能、识别技能并调用终端;附中文译文。
- 原作者:
- Agent Skills 项目贡献者
- 原文:
- Quickstart ↗
- 核对日期:
- 2026 年 10 月 17 日
核验范围
官方 PowerShell 掷 d20 命令实际运行 1,000 次,所有结果在 1 至 20 之间;目录与 VS Code 文档交叉核对。
未在 Copilot 账号中完成技能触发测试。命令可执行不等于模型必然会调用终端。
中文译文
中文译文由作舟整理,代码保持原样;原文完整保留在下方。 排版与相对链接已转换,未执行原文中的代码;交叉核验补充另列。转载与译文遵循 CC BY 4.0,不代表原作者为本站背书。
快速开始:创建第一个 Agent Skill
在本教程中,你将创建一个使用随机数生成器掷骰子的技能。
准备条件
- 安装 VS Code,并具备 GitHub Copilot。
本教程以 VS Code 为例。Agent Skills 是开放格式,同一技能也可用于 Claude Code、OpenAI Codex 等兼容 Agent。
创建技能
技能是一个包含 SKILL.md 文件的文件夹。VS Code 默认在 .agents/skills/ 中查找技能。在项目中创建 .agents/skills/roll-dice/SKILL.md:
---
name: roll-dice
description: Roll dice using a random number generator. Use when asked to roll a die (d6, d20, etc.), roll dice, or generate a random dice roll.
---
To roll a die, use the following command that generates a random number from 1
to the given number of sides:
```bash
echo $((RANDOM % <sides> + 1))
```
```powershell
Get-Random -Minimum 1 -Maximum (<sides> + 1)
```
Replace `<sides>` with the number of sides on the die (e.g., 6 for a standard
die, 20 for a d20).
这样就完成了:一个不到 20 行的文件。各部分的作用是:
name:技能的简短标识,必须与文件夹名称一致。description:告诉 Agent 何时使用技能,Agent 据此判断是否激活它。- 正文:技能激活后要遵循的指令。这里要求 Agent 执行终端命令生成随机数,并根据用户要求替换骰子面数。
试用
- 在 VS Code 中打开项目。
- 打开 Copilot Chat 面板。
- 在聊天面板底部的模式下拉框中选择 Agent。
- 输入
/skills,确认列表中出现roll-dice。如果没有,检查文件相对于项目根目录的位置是否为.agents/skills/roll-dice/SKILL.md。 - 发送:“Roll a d20”。
Agent 应当激活 roll-dice 技能。它可能请求运行终端命令的权限,允许后,会运行命令并返回 1 到 20 之间的随机数。
不同模型调用工具的可靠程度不同。有的模型会持续按照技能指令运行命令,有的可能自行回答。如果没有运行终端命令,可以在模型下拉框中换一个模型再试。
背后的过程
- 发现:聊天会话开始时,Agent 扫描默认技能目录并找到该技能,只读取
name和description,用于判断相关性。 - 激活:用户要求掷骰子时,问题与技能描述匹配,Agent 加载完整
SKILL.md正文。 - 执行:Agent 按正文指令操作,根据用户要求的面数调整终端命令。
这个过程使用渐进式披露,让 Agent 可以使用许多技能,而不必预先加载所有指令。
接下来可以看
你已经创建了一个可工作的 Agent Skill。可以继续阅读:
查看完整英文原文
title: "Quickstart"
description: "Create your first Agent Skill and see it work in VS Code."
In this tutorial, you'll create a skill that gives an agent the capability to roll dice using a random number generator.
Prerequisites
- VS Code with GitHub Copilot
This tutorial uses VS Code, but Agent Skills are an open format. The same skill works in any compatible agent, including Claude Code and OpenAI Codex.
Create the skill
A skill is a folder containing a SKILL.md file. VS Code looks for skills in .agents/skills/ by default. Create .agents/skills/roll-dice/SKILL.md in your project:
---
name: roll-dice
description: Roll dice using a random number generator. Use when asked to roll a die (d6, d20, etc.), roll dice, or generate a random dice roll.
---
To roll a die, use the following command that generates a random number from 1
to the given number of sides:
```bash
echo $((RANDOM % <sides> + 1))
```
```powershell
Get-Random -Minimum 1 -Maximum (<sides> + 1)
```
Replace `<sides>` with the number of sides on the die (e.g., 6 for a standard
die, 20 for a d20).
That's it — one file, under 20 lines. Here's what each part does:
name— A short identifier for the skill. Must match the folder name.description— Tells the agent when to use this skill. This is how the agent decides whether to activate it.- The body — Instructions the agent follows when the skill activates. Here, the agent is instructed to generate a random number using a terminal command, substituting the number of sides from the user's request.
Try it out
- Open your project in VS Code.
- Open the Copilot Chat panel.
- Select Agent mode from the mode dropdown at the bottom of the chat panel.
- Type
/skillsto confirm thatroll-diceappears in the list. If it doesn't, check that the file is at.agents/skills/roll-dice/SKILL.mdrelative to your project root. - Ask: "Roll a d20"
The agent should activate the roll-dice skill. It may ask for permission to run a terminal command — allow it. It will run the command and return a random number between 1 and 20.
Tool-use reliability varies across models — some follow skill instructions and run commands consistently, while others may attempt to answer on their own. If the agent responds without running a terminal command, try selecting a different model from the model dropdown.
How it works
Here's what happened behind the scenes:
Discovery — When the chat session started, the agent scanned default skill directories and found your skill. It read only the
nameanddescription, just enough to know when the skill might be relevant.Activation — When you asked about rolling dice, the agent matched your question to the skill's description and loaded the full
SKILL.mdbody into context.Execution — The agent followed the instructions in the body, adapting the terminal command to the number of sides in your request.
This process uses progressive disclosure to let the agent access many skills without loading all their instructions up front.
Next steps
You've created a working Agent Skill. From here:
- Best practices — How to write skills that are well-scoped and effective.
- Optimizing skill descriptions — Test and improve your skill's description so it activates on the right prompts.
- Specification — The complete format reference for
SKILL.mdfiles. - Example skills — Browse real-world skills on GitHub.
原文快照 SHA-256:a6614e814e19fb505b2e45a39a61643d62ac4ebee0515ceb913d09512d8489db
交叉核验补充
以下为本站核对说明,与上方原教程区分展示。
实测与原教程的边界
实测只将原命令的 <sides> 替换为 20。未创建新的练习技能,也未更改原文件指令。中文译文中的代码保持原样。