什么是 Agent Skills?初学者指南

发布: (2026年3月5日 GMT+8 02:27)
8 分钟阅读
原文: Dev.to

Source: Dev.to

(请提供您希望翻译的具体文本内容,我将按照要求保留源链接、格式和代码块,仅翻译正文部分。)

概览

AI 代理功能强大,但它们一开始是通用的。它们掌握了大量通用信息,却缺乏 的领域专属知识、偏好和团队约定。
技能 是一套可复用、独立的指令,教会代理按照 想要的方式执行特定任务。可以把它想象成给一位技艺高超的厨师的配方卡:厨师可以烹饪任何菜式,但配方卡明确告诉他如何制作 的秘制酱汁。

  • 没有技能 → 代理会产生通用的输出。
  • 有了技能 → 代理遵循您精确的指令,每次都交付您期望的结果。

在最简单的情况下,技能只需要一个文件:SKILL.md,其中包含名称、描述和指令。之后您可以添加脚本、资源或评估文件,但这些都是可选的。

下面是创建 good‑morning 技能的逐步指南。

步骤指南

1️⃣ 创建文件夹结构

你可以将技能放在以下任意根文件夹下:.agents/.github/.claude/。在 Copilot、Claude Code 以及其他工具中通用的约定是 .agents/skills/

your-project/
└── .agents/
    └── skills/
        └── good-morning/

2️⃣ 添加 SKILL.md 文件

good-morning/ 中创建一个名为 SKILL.md(全大写——这是代理定位文件的方式)的文件。

your-project/
└── .agents/
    └── skills/
        └── good-morning/
            └── SKILL.md

3️⃣ 添加 YAML 前置元数据

打开 SKILL.md 并在最顶部插入以下前置元数据:

---
name: good-morning
description: "A skill that responds to a good‑morning greeting with a cheerful reply"
---

重要说明

  • name 必须 与文件夹名称 (good-morning) 完全一致。若不一致,大多数编辑器(以及代理)会给出警告。
  • description 应简短、具体,并使用普通语言。它帮助代理决定何时加载此技能。

4️⃣ 编写技能说明

前置元数据下方的所有内容即为技能正文。只有在调用该技能时,这段文字才会被加入代理的上下文,从而保持整体提示大小较小。

---
name: good-morning
description: "A skill that responds to a good‑morning greeting with a cheerful reply"
---

# Good Morning Skill

**Trigger:** When the user says “good morning”.

**Response:**  

1. Greet the user personally.  
   - Example: `Hi Debbie, hope you have a great day!`  
2. Ask about their physical activity today.  
   - Example: `Did you get a chance to do any sport today?`  
3. Include a light‑hearted sports‑related joke.  
   - Example: `Why did the basketball team go to the bank? Because they wanted to get their *rebound*!`

**Formatting guidelines:**  

- Keep the reply concise (2‑3 sentences).  
- Use a friendly, upbeat tone.  
- End with the joke on a new line for emphasis.

**Optional extras (add later if needed):**  

- `script.sh` – a helper script to fetch the user’s name from a config file.  
- `assets/` – images or emojis to sprinkle into the response.  
- `eval.md` – test cases to verify the skill behaves as expected.

Recap

步骤您的操作结果
1创建 .agents/skills/good-morning/ 文件夹标准位置,兼容跨工具
2添加 SKILL.md(大写)代理能够发现该技能
3插入包含匹配 name 的 YAML front‑matter为代理提供快速元数据
4编写清晰、可操作的指令定义代理应遵循的具体行为

您现在已经拥有一个完整可用的 good‑morning 技能!以后可以随意添加脚本、资源或评估文件进行扩展,但仅凭 SKILL.md 就足以让代理开始使用它。祝您构建愉快!

Source:

示例

用户: Good morning

助手:

Hi Debbie, have you done any sport today? Here's a funny joke about sports: 
Why did the soccer player bring string to the game? Because he wanted to tie the score!

这就是完整的技能——只需要一个文件、几行指令。可以随意个性化(加入你的名字、修改话题等)。

如何尝试

  1. 在同一目录下启动一个新会话(技能会在会话开始时被发现)。
  2. 输入:
Good morning

代理会定位到 SKILL.md 文件,读取内容并作出响应。

  • GitHub Copilot 中,你会看到类似下面的内容:

    “Hi Debbie, have you done any sport today? Here’s a funny joke about sports! Why did the bicycle fall over? Because it was too tired from all that cycling!”

  • Claude Code 中,你会得到:

    “Hi Debbie, have you done any sport today? Here’s a funny joke for you: Why do basketball players love donuts? Because they can always dunk them!”

同一个 SKILL.md 可以在 Copilot、Claude Code 以及其他代理之间通用。每个代理都会发现该技能,读取指令并执行。

技能能做什么

用以下指令替换简单的 “good morning” 示例:

  • 生成一份精致的 README
  • 按团队的格式编写提交信息
  • 根据你的标准审查代码

相同的模式,却产生更大的影响。

三层级高效加载

级别加载时机包含内容典型大小
1始终在代理的上下文中名称 + 简短描述(约 100 词)极小
2当技能被触发时完整的 SKILL.md 正文(说明、步骤、示例)≤ 500 行
3按需加载脚本、引用、资源(仅在需要时)可变;可能根本不被加载

由于上下文窗口有限,设计良好的技能会在顶部(级别 1)保持精简,仅在需要时才拉取详细信息。

技能的安装位置

项目级别(仅在项目目录内部可用)

your-project/.github/skills/
your-project/.claude/skills/
your-project/.agents/skills/

全局(在任何目录均可使用)

~/.copilot/skills/
~/.claude/skills/
~/.agents/skills/

注意:
.agents/skills/ 路径遵循 Agent Skills 开放标准(跨工具)。Claude Code 使用其自己的 .claude/ 结构,而不是 .agents/

安装和管理技能

社区在 skills.sh 中维护了技能目录,您可以浏览。

安装技能

npx skills add anthropics/skills --skill skill-creator

从 Anthropic 安装 skill‑creator 技能——用于构建其他技能的辅助工具。

列出已安装的技能

npx skills list

搜索技能

npx skills find

skills CLI 会自动将技能放置在每个代理(Copilot、Claude Code、Cursor、Goose 等)的正确位置。

Bottom line

技能体积小、可移植,并可在多个 AI 代理之间使用。 通过保持顶层描述简短,并在需要时才加载详细指令,您可以在不超出 token 限制的前提下,最大化每个技能的实用性。

0 浏览
Back to Blog

相关文章

阅读更多 »