世界上有一种技术叫OpenClaw Skills,它就像给AI装上了瑞士军刀。 每个Skill都是一把精心打磨的工具,而SKILL.md就是它的说明书。今天,我要教你从零开始打造属于自己的Skills。
📋 什么是OpenClaw Skills?
OpenClaw Skills是Agent能力的模块化封装。每个Skill包含:
- SKILL.md - 技能描述文件,告诉AI这个Skill能做什么
- 工具函数 - 实际执行任务的代码
- 配置项 - 环境变量、API密钥等
Skills遵循AgentSkills标准,这意味着你的Skill可以在任何兼容的Agent平台上运行。
🚀 快速开始:创建你的第一个Skill
1
创建Skill目录结构
my-skill/
├── SKILL.md # 技能描述文件
├── README.md # 使用说明
└── src/
└── tools.py # 工具实现(可选)
2
编写SKILL.md
SKILL.md使用YAML frontmatter + Markdown格式:
---
name: web_search
version: 1.0.0
description: 使用DuckDuckGo搜索网络内容
author: your-name
tags: [search, web, automation]
tools:
- name: search
description: 执行网络搜索
parameters:
query:
type: string
description: 搜索关键词
required: true
count:
type: number
description: 返回结果数量
default: 5
---
# Web Search Skill
这是一个网络搜索技能,使用DuckDuckGo作为搜索源。
## 使用示例
```yaml
action: search
parameters:
query: "OpenClaw tutorial"
count: 10
```
## 注意事项
- 免费API有速率限制
- 支持中文搜索
- 结果包含标题、URL和摘要
3
部署到OpenClaw
将Skill文件夹放入OpenClaw的skills目录:
# 本地路径
~/.config/openclaw/skills/my-skill/
# 或者系统路径
/etc/openclaw/skills/my-skill/
🎯 SKILL.md详解
YAML Frontmatter字段
| 字段 | 类型 | 说明 |
|---|---|---|
| name | string | Skill唯一标识,小写+下划线 |
| version | string | 遵循SemVer版本规范 |
| description | string | 一句话描述Skill功能 |
| author | string | 作者名称或组织 |
| tags | array | 分类标签,便于检索 |
| tools | array | 该Skill提供的工具列表 |
工具参数定义
tools:
- name: send_email
description: 发送邮件
parameters:
to:
type: string
description: 收件人邮箱
required: true
subject:
type: string
description: 邮件主题
required: true
body:
type: string
description: 邮件正文
required: true
attachments:
type: array
description: 附件列表
required: false
items:
type: string
💡 最佳实践
🎭 妙用风格指南
- 描述要具体:不说"搜索网页",而说"使用DuckDuckGo搜索网络内容,返回标题、URL和摘要"
- 示例要真实:提供3个以上不同场景的调用示例
- 边界要说清:明确说明限制条件和错误处理
命名规范
- Skill名称:小写字母+数字+下划线,如
web_search、file_manager - 工具名称:动词开头,如
search、send、create - 参数名称:驼峰或下划线,保持一致
错误处理
# 好的错误处理
tools:
- name: fetch_url
description: 获取网页内容,支持超时和重试
parameters:
url:
type: string
description: 目标URL,必须以http://或https://开头
required: true
timeout:
type: number
description: 超时时间(秒),默认30
default: 30
retries:
type: number
description: 失败重试次数,默认3
default: 3
errors:
- code: TIMEOUT
description: 请求超时,请检查网络或增加timeout参数
- code: INVALID_URL
description: URL格式错误,请确保包含协议头
🔧 高级技巧
条件加载
根据环境条件决定是否加载Skill:
---
name: browser_automation
condition:
env:
- PLAYWRIGHT_ENABLED=true
binary:
- playwright
---
依赖管理
---
name: advanced_search
dependencies:
skills:
- web_search >= 1.0.0
- text_analysis >= 2.1.0
packages:
- beautifulsoup4
- requests
---
权限控制
---
name: database_access
permissions:
- database:read
- database:write
- file:read
sensitive: true # 标记为敏感操作,需要确认
---
📚 完整示例:RSS聚合Skill
---
name: rss_aggregator
version: 2.0.0
description: 抓取RSS订阅源,提取文章标题、链接和摘要
author: miaoquai
tags: [rss, feed, news, automation]
tools:
- name: fetch_feed
description: 获取RSS订阅源内容
parameters:
url:
type: string
description: RSS订阅源URL
required: true
limit:
type: number
description: 返回文章数量上限
default: 10
returns:
type: array
items:
type: object
properties:
title:
type: string
link:
type: string
description:
type: string
pubDate:
type: string
- name: parse_feed
description: 解析本地RSS文件
parameters:
file_path:
type: string
description: RSS文件路径
required: true
---
# RSS聚合技能
自动抓取RSS订阅源,支持过滤、排序和导出。
## 使用场景
- 每日新闻聚合
- 博客更新监控
- 竞品动态追踪
## 示例调用
```yaml
# 获取OpenAI博客
action: fetch_feed
parameters:
url: "https://openai.com/blog/rss.xml"
limit: 5
# 解析本地文件
action: parse_feed
parameters:
file_path: "/data/feeds/tech.xml"
```
## 输出格式
```json
[
{
"title": "GPT-5发布",
"link": "https://openai.com/blog/gpt-5",
"description": "更强大的多模态模型...",
"pubDate": "2026-04-15T08:00:00Z"
}
]
```
⚠️ 常见坑点
- 忘记在parameters中标记required: true,导致AI调用时遗漏必填参数
- description写得过于笼统,AI无法准确理解工具用途
- returns定义不清,下游处理时出错
- 忽略错误处理场景,API失败时无反馈
🎓 学习路径
- 入门:模仿现有Skills,修改参数和描述
- 进阶:组合多个工具,实现复杂工作流
- 精通:编写带条件判断、错误重试的 robust Skill
- 大师:发布到ClawHub,服务整个社区