
Agent Skills 深度解析:为 AI 代理构建可复用的技能生态系统
背景
一个真实的故事
两周前,KiloCode 发布了 v4.141.0 版本,这个版本带来了一个重要特性:原生支持 Agent Skills。
在此之前,我在 KiloCode 中使用 skills 需要在一个 main rule 中手动 list 所有技能。每次添加新技能都需要:
<!-- 旧方式:在 main rule 中手动维护 -->
# AVAILABLE SKILLS
Skills are pre-packaged instructions. When a task matches a skill,
use read_file to load the SKILL.md and follow its instructions.
Available skills:
- **frontend-design**: Create distinctive UI components
Location: ~/.kilocode/skills/frontend-design/SKILL.md
- **code-review**: Automated code quality analysis
Location: ~/.kilocode/skills/code-review/SKILL.md
- **pdf-processing**: PDF manipulation toolkit
Location: ~/.kilocode/skills/pdf-processing/SKILL.md
To use: read_file the location → follow instructions
这种方式的问题显而易见:
- 维护负担重:每添加一个技能都要修改 main rule(name + description + location)
- 容易出错:忘记更新列表或路径写错导致技能 " 失踪 "
- 扩展性差:技能多了列表会变得臃肿,提示词越来越长
- 不够优雅:违背了模块化的初衷,信息重复维护
而在 v4.141.0 之后,一切都变了:
# 新方式:只需将技能放入目录
~/.kilocode/skills/
├── frontend-design/
│ └── SKILL.md
├── code-review/
│ └── SKILL.md
└── pdf-processing/
└── SKILL.md
# KiloCode 自动发现并加载!
零配置,自动发现 - 这才是技能管理的正确打开方式。
这个改进让我意识到:Agent Skills 不仅仅是一个规范,更代表了 AI 代理能力管理的未来方向。
行业面临的挑战
在 AI 代理(AI Agent)快速发展的今天,我们面临一个关键挑战:如何让 AI 代理高效地学习和使用新技能?
传统做法是将所有指令塞进系统提示词,但这会导致:
- 上下文爆炸:提示词过长,成本飙升
- 维护困难:修改一个功能需要重构整个提示词
- 无法复用:不同代理之间无法共享能力
- 扩展受限:添加新功能需要重新设计架构
Agent Skills 规范应运而生,它提供了一种标准化、模块化的方式来扩展 AI 代理的能力。本文将深入探讨 Agent Skills 的设计理念、技术实现和实战应用。
什么是 Agent Skills?
核心概念
Agent Skills 是一个开放格式规范,用于通过可发现的指令、脚本和资源文件夹来赋予 AI 代理新能力。它的核心特点是:
Write Once, Use Everywhere
一次编写,到处使用
一个技能可以被多个 AI 代理使用,无论是 Claude Desktop、Cursor、还是 Kilo Code。
设计哲学
Agent Skills 基于三个核心设计原则:
1. 渐进式披露(Progressive Disclosure)
这是 Agent Skills 最重要的创新点。代理在启动时只加载技能的元数据(名称和描述),只有在需要时才加载完整指令。
启动时:加载所有技能的 name + description(几百字节)
↓
匹配任务:识别相关技能
↓
执行时:读取完整的 SKILL.md 指令(几KB)
↓
需要时:加载脚本、资源文件(按需)
对比传统方式:
- 传统:所有指令都在系统提示词中(50-100KB)
- Skills:启动时只有元数据(1-2KB),按需加载(5-10KB)
效果:
- 减少 95% 的初始上下文消耗
- 支持数百个技能而不影响性能
- 降低 API 调用成本
2. 模块化与可组合性
每个技能都是独立的目录,包含:
skill-name/
├── SKILL.md # 必需:指令 + 元数据
├── scripts/ # 可选:可执行代码
│ ├── process.py
│ └── helper.sh
├── references/ # 可选:参考文档
│ └── api-docs.md
└── assets/ # 可选:模板、资源
└── template.json
这种结构带来的好处:
- 隔离性:技能之间互不干扰
- 可测试:每个技能可独立测试
- 可版本化:使用 Git 管理技能版本
- 可复用:在多个项目间共享
3. 跨平台兼容性
统一的规范让技能可以在不同代理间使用:
| 代理 | 技能目录 | 类型 |
|---|---|---|
| Claude Desktop | ~/.claude/skills/ | 全局 |
| Cursor | .cursor/skills/ | 项目级 |
| Kilo Code | ~/.kilocode/skills/ | 全局 |
| GitHub Copilot | .github/skills/ | 项目级 |
| Windsurf | .windsurf/skills/ | 项目级 |
SKILL.md 规范详解
基本结构
一个标准的 SKILL.md 文件包含两部分:
---
name: skill-identifier
description: A concise description of what this skill does
tags: [tag1, tag2]
version: 1.0.0
author: Your Name
dependencies: []
---
# Skill Name
## When to use this skill
Explain when and why to use this skill...
## Instructions
Step-by-step guide on how to perform the task...
## Examples
Concrete examples showing the skill in action...
## Best Practices
Tips and recommendations...
YAML Frontmatter 字段
必需字段
name: pdf-processing # 技能唯一标识符
description: | # 简洁的功能描述
Extract text and tables from PDF files,
fill forms, merge documents
推荐字段
tags: [pdf, document, extraction] # 便于分类和搜索
version: 1.2.0 # 语义化版本
author: John Doe # 作者信息
license: MIT # 开源协议
高级字段
dependencies: # 依赖的其他技能
- skill: python-development
version: ">=1.0.0"
- skill: file-operations
version: "*"
modes: [code, ask, debug] # 适用的代理模式
requires: # 外部依赖
python: ">=3.8"
packages:
- pdfplumber>=0.10.0
- PyPDF2>=3.0.0
Markdown 主体内容
1. When to use this skill(触发条件)
这是最关键的部分,告诉代理何时激活这个技能:
## When to use this skill
Use this skill when the user needs to:
- Extract text or tables from PDF documents
- Read PDF forms and extract field data
- Merge multiple PDFs into one document
- Fill out PDF forms programmatically
- Split PDF files into separate pages
最佳实践:
- 使用具体的动词(extract, create, analyze)
- 列举明确的使用场景
- 包含关键词以便匹配
2. Instructions(执行指令)
详细的步骤说明:
## Instructions
### Step 1: Analyze the PDF
First, determine what operation the user wants:
- Text extraction → Use pdfplumber
- Form filling → Use PyPDF2
- Merging → Use PyPDF2.PdfMerger
### Step 2: Execute the operation
For text extraction:
1. Import pdfplumber
2. Open the PDF file
3. Extract text from each page
4. Return formatted results
[Code example here]
3. Examples(示例代码)
提供可直接运行的代码:
## Examples
### Example 1: Extract text from PDF
\`\`\`python
import pdfplumber
def extract_text(pdf_path):
with pdfplumber.open(pdf_path) as pdf:
text = ""
for page in pdf.pages:
text += page.extract_text()
return text
# Usage
text = extract_text("document.pdf")
print(text)
\`\`\`
技术实现原理
Agent 侧实现
让我们深入了解 AI 代理如何集成和使用 Skills。以 KiloCode 为例,看看现代 AI 代理是如何实现自动技能发现的。
KiloCode v4.141.0 的突破
发布时间: 两周前(2025 年 12 月底)
在 v4.141.0 之前,技能管理是这样的:
<!-- 旧方式:在 main rule 中手动维护 -->
# AVAILABLE SKILLS
Skills are pre-packaged instructions for specific tasks. When a user request matches a skill description, read the full SKILL.md file to get detailed instructions.
These are the currently available skills:
- **frontend-design**: Create distinctive, production-grade UI components
- Location: ~/.kilocode/skills/frontend-design/SKILL.md
- Use read_file tool to load this skill when needed
- **code-review**: Automated code quality analysis with specialized patterns
- Location: ~/.kilocode/skills/code-review/SKILL.md
- Use read_file tool to load this skill when needed
- **pdf-processing**: Comprehensive PDF manipulation toolkit
- Location: ~/.kilocode/skills/pdf-processing/SKILL.md
- Use read_file tool to load this skill when needed
...(每添加技能都要手动更新这个列表)
## How to use skills
1. Identify which skill matches the user's request based on the description
2. Use read_file to load the full SKILL.md file from the location shown
3. Follow the instructions in the skill file
4. Access any bundled files (scripts, references, assets) as needed
问题明显:
- 维护负担重:每次添加技能都要修改 main rule,添加 name、description、location 三项信息
- 容易出错:忘记更新列表导致技能 " 失踪 “,或者路径写错
- 扩展性差:技能多了列表会变得臃肿,main rule 文件越来越大
- 不够优雅:违背了模块化的初衷,一处改动影响全局
- 重复劳动:信息已经在 SKILL.md 的 frontmatter 中,还要重复维护
v4.141.0 的改进:自动发现机制
// KiloCode 新实现(简化版)
async function discoverSkills(skillsDir: string): Promise<Skill[]> {
const skills: Skill[] = [];
const entries = await fs.readdir(skillsDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory()) {
const skillPath = path.join(skillsDir, entry.name);
const skillMd = path.join(skillPath, 'SKILL.md');
if (await fs.pathExists(skillMd)) {
const skill = await loadSkillMetadata(skillMd);
skills.push(skill);
}
}
}
return skills;
}
// 启动时自动发现
const skills = await discoverSkills('~/.kilocode/skills/');
console.log(`Auto-discovered ${skills.length} skills`);
使用体验对比:
| 操作 | v4.141.0 之前 | v4.141.0 之后 |
|---|---|---|
| 添加新技能 | 1. 创建目录 2. 编写 SKILL.md 3. 更新 main rule 4. 重启代理 | 1. 创建目录 2. 编写 SKILL.md 自动生效 |
| 删除技能 | 1. 删除目录 2. 更新 main rule 3. 重启代理 | 1. 删除目录 自动生效 |
| 技能数量限制 | ~10 个(提示词太长) | 数百个(按需加载) |
实际效果:
# 现在的工作流
$ cd ~/.kilocode/skills/
$ npx ai-agent-skills install frontend-design
✓ Installed to ~/.kilocode/skills/frontend-design
# 立即在 KiloCode 中可用,无需任何配置!
# 当你说:"Create a pricing card"
# KiloCode 自动:
# 1. 扫描到 frontend-design 技能
# 2. 匹配到 "Create" 和 "pricing card" 关键词
# 3. 加载完整 SKILL.md 指令
# 4. 按照指令生成高质量组件
这个改进让 KiloCode 成为首批原生支持 Agent Skills 规范的 AI 代理之一,真正实现了 " 零配置,开箱即用 “。
KiloCode 的技术实现细节
想深入了解 KiloCode 是如何实现自动技能发现的?以下是关键代码:
1. Skills 提示词生成
src/core/prompts/sections/skills.ts
这个文件负责生成技能相关的提示词部分:
// 自动生成的提示词格式
AVAILABLE SKILLS
Skills are pre-packaged instructions for specific tasks.
When a user request matches a skill description, read the full
SKILL.md file to get detailed instructions.
- These are the currently available skills for "${currentMode}" mode:
${skillsList}
To use a skill:
1. Identify which skill matches the user's request based on the description
2. Use read_file to load the full SKILL.md file from the path shown in brackets
3. Follow the instructions in the skill file
4. Access any bundled files (scripts, references, assets) as needed
2. 系统提示词集成
src/core/prompts/system.ts
Skills 提示词被自动注入到系统提示词中,成为 AI 代理能力的一部分。
关键设计:
- 懒加载:启动时只加载技能元数据(name + description)
- 渐进式披露:需要时才读取完整 SKILL.md
- 按需加载:根据任务匹配相关技能
- 模式感知:不同模式可以有不同的技能集
这种设计让 KiloCode 能够支持数百个技能而不影响启动速度和运行效率。
工作流程图
用户请求: "Extract text from PDF"
↓
Step 1: 技能匹配
├─ 扫描所有技能元数据
├─ 关键词匹配: "PDF", "extract"
└─ 找到: pdf-processing
↓
Step 2: 技能激活
├─ 读取完整 SKILL.md
├─ 注入系统提示词
└─ 加载相关脚本/资源
↓
Step 3: 执行任务
├─ 按照指令步骤执行
├─ 调用脚本(如需要)
└─ 返回结果
↓
Step 4: 技能卸载
└─ 从上下文中移除(为下次任务腾出空间)
技能管理:从手动到自动化
技能管理的挑战
前面我们深入了解了 KiloCode 如何在代理层面实现技能的自动发现和加载。但对于开发者和团队来说,还有另一个重要问题:如何高效地管理和分发技能?
想象这样的场景:
- 你开发了一个很棒的技能,想分享给团队使用
- 团队成员使用不同的 AI 代理(Claude、Cursor、KiloCode),都需要安装
- 技能有新版本时,需要通知所有人手动更新
- 想使用社区的优秀技能,但不知道去哪里找
这些问题的核心是:缺少统一的技能包管理工具。
就像 npm 对 JavaScript、pip 对 Python 一样,Agent Skills 生态也需要一个包管理器。
AI Agent Skills CLI:统一的技能管理器
AI Agent Skills CLI 应运而生。它是一个类似 Homebrew 的包管理器,专门用于管理 AI 代理技能,解决了上述所有痛点。
核心特性
1. 多源安装
# 从内置库安装
npx ai-agent-skills install pdf-processing
# 从 GitHub 安装
npx ai-agent-skills install anthropics/skills/pdf
# 从本地路径安装
npx ai-agent-skills install ./my-custom-skill
2. 多代理支持
支持 11 个主流 AI 代理:
# 安装到特定代理
npx ai-agent-skills install frontend-design --agent cursor
# 安装到 Claude Desktop
npx ai-agent-skills install code-review --agent claude
# 安装到 KiloCode(即将支持)
npx ai-agent-skills install pdf-processing --agent kilocode
注意: KiloCode 支持已通过 PR #4 提交,目前正在审核中。合并后即可使用
--agent kilocode参数。
3. 交互式浏览器
npx ai-agent-skills browse
提供类似 brew search 的体验:
- 分类浏览(开发/文档/创意/商业/生产力)
- 关键词搜索
- 技能详情预览
- 快速安装
4. Dry Run 模式
预览操作而不实际执行:
npx ai-agent-skills install pdf --agent kilocode --dry-run
输出:
Would install: pdf
Agent: kilocode
Source: /Users/addo/Workspaces/github_w/Ai-Agent-Skills/skills/pdf
Destination: /Users/addo/.kilocode/skills/pdf
Size: 2.4 KB
Note: Would overwrite existing installation
技能目录结构
CLI 管理的技能库包含 40+ 精选技能:
skills-registry/
├── development/ # 开发类 (13个)
│ ├── frontend-design/
│ ├── code-review/
│ ├── mcp-builder/
│ └── ...
├── documents/ # 文档类 (4个)
│ ├── pdf/
│ ├── excel/
│ └── ...
├── creative/ # 创意类 (6个)
│ ├── canvas-design/
│ └── ...
├── business/ # 商业类 (5个)
│ └── ...
└── productivity/ # 生产力类 (12个)
└── ...
实战案例
案例 1:为新项目配置开发环境
场景: 启动一个新的前端项目,需要 AI 代理具备以下能力:
- 创建精美的 UI 组件
- 进行代码审查
- 编写单元测试
解决方案:
# Step 1: 安装必要技能到 KiloCode
npx ai-agent-skills install frontend-design --agent kilocode
npx ai-agent-skills install code-review --agent kilocode
npx ai-agent-skills install qa-testing --agent kilocode
# Step 2: 验证安装
npx ai-agent-skills list --installed --agent kilocode
使用效果:
在 KiloCode 中,当你说:“Create a modern pricing card component”,代理会:
- 自动激活
frontend-design技能 - 根据技能指令生成高质量代码
- 应用最佳实践和设计原则
生成的效果:
![[front-design-sample.png]]
案例 2:团队统一技能配置
场景: 团队使用不同的 AI 代理(Claude、KiloCode、Cursor),需要统一技能集。
解决方案:
为每个代理创建安装脚本:
#!/bin/bash
# setup-kilocode-skills.sh
echo "Installing skills to KiloCode..."
skills=(
"frontend-design"
"code-review"
"python-development"
"qa-regression"
"git-workflow"
)
for skill in "${skills[@]}"; do
npx ai-agent-skills install "$skill" --agent kilocode
echo "✓ Installed $skill to KiloCode"
done
echo "KiloCode skills setup complete!"
类似地创建 setup-claude-skills.sh、setup-cursor-skills.sh 等。
效果:
- 团队成员根据使用的代理运行对应脚本
- 一致的代码质量标准
- 统一的工作流程
案例 3:开发和测试自定义技能
场景: 为公司内部 API 创建自定义技能。
步骤 1:创建技能结构
mkdir -p ~/my-skills/company-api
cd ~/my-skills/company-api
创建 SKILL.md:
---
name: company-api
description: Interact with our internal company APIs
version: 1.0.0
author: DevTeam
---
# Company API Integration
## When to use this skill
Use this skill when you need to:
- Query employee database
- Fetch project information
- Update task status
## Instructions
### Authentication
All API calls require a token:
\`\`\`python
import os
token = os.getenv('COMPANY_API_TOKEN')
headers = {'Authorization': f'Bearer {token}'}
\`\`\`
### Query Employees
\`\`\`python
import requests
def get_employee(employee_id):
response = requests.get(
f'https://api.company.com/employees/{employee_id}',
headers=headers
)
return response.json()
\`\`\`
步骤 2:本地测试
# 从本地路径安装到 KiloCode
npx ai-agent-skills install ~/my-skills/company-api --agent kilocode
# 在 KiloCode 中测试
# 输入:"Get employee info for ID 12345"
# 代理应该激活 company-api 技能并执行查询
步骤 3:发布和共享
# 推送到 GitHub
cd ~/my-skills/company-api
git init
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:company/ai-skills.git
git push -u origin main
# 团队成员可以直接安装
npx ai-agent-skills install company/ai-skills/company-api
高级技巧
技巧 1:动态脚本执行
技能可以包含可执行脚本:
diagnostic-skill/
├── SKILL.md
└── scripts/
├── analyze.py # 分析脚本
├── fix.py # 修复脚本
└── verify.sh # 验证脚本
在 SKILL.md 中引用:
## Step 3: Run Diagnostics
Execute the analysis script:
\`\`\`bash
python scripts/analyze.py --input data.json
\`\`\`
The script will output a detailed report.
技巧 2:使用 Assets 目录
存储模板和配置文件:
template-generator/
├── SKILL.md
└── assets/
├── react-component.template
├── api-route.template
└── test-suite.template
在指令中引用:
## Generate React Component
Use the template from `assets/react-component.template`:
\`\`\`javascript
// Load template
const template = readFile('assets/react-component.template');
// Customize based on user requirements
const component = template.replace('{{name}}', componentName);
\`\`\`
与其他方案对比
Agent Skills vs. 系统提示词
| 维度 | 系统提示词 | Agent Skills |
|---|---|---|
| 上下文大小 | 50-100 KB(全部加载) | 1-2 KB(元数据) + 按需加载 |
| 可维护性 | 困难(单一大文件) | 简单(模块化) |
| 可复用性 | 无法跨项目 | 跨项目、跨代理 |
| 扩展性 | 受限于上下文窗口 | 支持数百个技能 |
| 成本 | 高(每次都发送) | 低(按需加载) |
| 版本管理 | 困难 | Git 友好 |
Agent Skills vs. Function Calling
| 维度 | Function Calling | Agent Skills |
|---|---|---|
| 适用场景 | 结构化 API 调用 | 复杂工作流程 |
| 灵活性 | 固定参数 | 自然语言指令 |
| 上下文 | 无法传递详细说明 | 包含完整指导 |
| 学习曲线 | 需要定义 schema | 纯 Markdown |
| 组合能力 | 有限 | 可组合技能 |
最佳实践: 结合使用
- Function Calling:简单的 API 调用
- Agent Skills:复杂的多步骤任务
Agent Skills vs. RAG
| 维度 | RAG | Agent Skills |
|---|---|---|
| 知识类型 | 被动知识库 | 主动执行指令 |
| 检索效率 | 向量搜索开销 | 直接元数据匹配 |
| 准确性 | 可能检索到无关内容 | 精确匹配 |
| 可执行性 | 仅提供信息 | 包含可执行代码 |
| 维护成本 | 需要向量数据库 | 文件系统即可 |
最佳实践
1. 编写高质量的 SKILL.md
好的例子
---
name: api-integration
description: |
Integrate with RESTful APIs including authentication,
error handling, and response parsing
tags: [api, rest, integration]
---
# API Integration
## When to use this skill
Use this skill when the user needs to:
- Connect to external REST APIs
- Handle OAuth authentication
- Parse and transform API responses
- Implement retry logic and error handling
## Prerequisites
- API endpoint URL
- Authentication credentials (API key, OAuth token, etc.)
- Required HTTP method (GET, POST, PUT, DELETE)
## Instructions
### Step 1: Analyze API Requirements
First, gather information:
- What is the base URL?
- What authentication method is used?
- What data needs to be sent/received?
### Step 2: Implement Authentication
[详细步骤...]
### Step 3: Make API Request
\`\`\`python
import requests
def make_api_call(url, method='GET', headers=None, data=None):
try:
response = requests.request(
method=method,
url=url,
headers=headers,
json=data,
timeout=30
)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"API call failed: {e}")
return None
\`\`\`
## Error Handling
Common errors and solutions:
- 401 Unauthorized → Check authentication credentials
- 429 Too Many Requests → Implement rate limiting
- 500 Server Error → Add retry logic with exponential backoff
## Examples
### Example 1: GET Request with API Key
\`\`\`python
headers = {'Authorization': f'Bearer {api_key}'}
data = make_api_call('https://api.example.com/users', headers=headers)
\`\`\`
### Example 2: POST Request with JSON Body
\`\`\`python
data = {'name': 'John', 'email': 'john@example.com'}
result = make_api_call(
'https://api.example.com/users',
method='POST',
headers=headers,
data=data
)
\`\`\`
避免的例子
---
name: api
description: API stuff
---
# API
Use this to call APIs.
## How to use
Just call the API.
\`\`\`python
import requests
response = requests.get(url)
\`\`\`
问题:
- 描述过于简单
- 缺少触发条件
- 没有详细步骤
- 代码示例不完整
- 没有错误处理
2. 合理的技能粒度
粒度平衡
太粗:
**不推荐:** super-developer-skill
包含前端、后端、数据库、测试所有内容
→ 太大,难以维护,很少全部使用
太细:
**不推荐:** add-console-log
只做一件事:添加 console.log
→ 太小,不值得单独创建技能
合适:
**推荐:** frontend-design
专注于前端 UI 组件设计
→ 边界清晰,复用价值高
**推荐:** code-review
专注于代码质量分析
→ 功能完整,独立使用
总结
Agent Skills 为 AI 代理带来了模块化、可复用的能力扩展方式。它的核心价值在于:
关键优势
- 渐进式披露 - 减少 95% 的初始上下文消耗
- 模块化设计 - 技能独立开发、测试、维护
- 跨平台兼容 - 一次编写,到处使用
- 社区驱动 - 开放的生态系统
开始使用
# 1. 安装 CLI
npx ai-agent-skills --version
# 2. 浏览技能
npx ai-agent-skills browse
# 3. 安装技能
npx ai-agent-skills install frontend-design
# 4. 开始使用
# 在你的 AI 代理中说:"Create a pricing card component"
延伸阅读
- Agent Skills 官方规范 - 完整的技能格式规范
- Agent Skills GitHub - 官方仓库和示例
- AI Agent Skills CLI - 技能管理命令行工具
- 技能浏览器 - 浏览和发现社区技能
- KiloCode 官网 - 原生支持 Agent Skills 的 AI 代理
Agent Skills 正在改变 AI 代理的工作方式。现在就加入这场革命,为你的 AI 代理解锁无限可能!
作者注:本文基于 Agent Skills v1.0 规范和 AI Agent Skills CLI bb174d5 编写。技术细节可能随版本更新而变化,请参考最新官方文档。



