如何写skill
·
OpenClaw 的 Skill 本质就是一个放在 skills/ 目录下的文件夹 + SKILL.md,用 Markdown 写 “什么时候用、怎么用、调用什么工具 / 脚本”,不用写复杂代码。下面按结构、模板、示例、调试一步步讲。
一、Skill 目录结构(最简)
plaintext
~/.openclaw/workspace/skills/
└── hello-skill/
└── SKILL.md # 唯一必须文件
可选扩展(放脚本 / 配置):
plaintext
hello-skill/
├── SKILL.md
├── scripts/
│ └── main.py # 自己写的执行脚本
└── assets/
└── config.json # 配置文件
二、SKILL.md 标准结构(三部分)
1. 头部元信息(Frontmatter)
yaml
---
name: hello-skill # 技能名,小写、无空格
description: 用户打招呼/问候时使用,输入名字返回问候语
user-invocable: true # 允许用户直接调用
triggers: ["打招呼", "问候", "你好"] # 触发关键词
metadata:
openclaw:
emoji: "👋"
requires:
bins: ["python3"] # 依赖命令
env: [] # 依赖环境变量
---
2. 技能说明(写给 AI 的手册)
markdown
# 打招呼技能
## 何时使用
- 用户说“你好”“打招呼”“问候”时
- 用户明确要求使用 hello-skill 时
## 输入参数
- username: 字符串,必填,用户名字
## 执行步骤
1. 检查 username 是否为空,为空则提示“请提供名字”
2. 调用脚本 scripts/main.py,传入 username
3. 返回脚本输出结果
## 输出格式
纯文本:Hello, {username}! 这是你的第一个 OpenClaw Skill 🎉
## 边界
- 只处理中文/英文名字
- 不处理敏感内容
3. 执行脚本(scripts/main.py,可选)
python
运行
import sys
def main():
if len(sys.argv) < 2:
print("请提供名字")
return
username = sys.argv[1]
print(f"Hello, {username}! 这是你的第一个 OpenClaw Skill 🎉")
if __name__ == "__main__":
main()
三、完整示例(可直接复制运行)
- 创建目录
bash
运行
mkdir -p ~/.openclaw/workspace/skills/hello-skill/scripts
- 写入 SKILL.md
bash
运行
nano ~/.openclaw/workspace/skills/hello-skill/SKILL.md
内容:
yaml
---
name: hello-skill
description: 用户打招呼/问候时使用,输入名字返回问候语
user-invocable: true
triggers: ["打招呼", "问候", "你好"]
metadata:
openclaw:
emoji: "👋"
requires:
bins: ["python3"]
---
# 打招呼技能
## 何时使用
- 用户说“你好”“打招呼”“问候”时
- 用户明确要求使用 hello-skill 时
## 输入参数
- username: 字符串,必填,用户名字
## 执行步骤
1. 检查 username 是否为空,为空则提示“请提供名字”
2. 执行命令:python3 scripts/main.py {username}
3. 返回结果
## 输出格式
纯文本:Hello, {username}! 这是你的第一个 OpenClaw Skill 🎉
- 写入脚本
bash
运行
nano ~/.openclaw/workspace/skills/hello-skill/scripts/main.py
内容同上 Python 代码。
- 加执行权限
bash
运行
chmod +x ~/.openclaw/workspace/skills/hello-skill/scripts/main.py
四、调试与验证
bash
运行
# 列出可用技能
openclaw skills list --eligible
# 查看技能详情
openclaw skills info hello-skill
在对话中测试:
- 输入:“你好,我叫小明”
- AI 自动调用 hello-skill,返回:Hello, 小明!...
五、进阶要点
- 参数默认值:减少 AI 询问,如
username: 字符串,默认"朋友" - 幂等设计:多次执行结果一致,避免重复操作openclaw.cocoloop.cn
- 敏感信息:用环境变量,不要硬编码 Keyopenclaw.cocoloop.cn
- 触发精准:
description写清楚场景,AI 才会自动调用
更多推荐



所有评论(0)