OpenClaw Skills 写法指南

一、Skills 的核心结构
一个标准 Skill 通常包含以下要素
# skills/your-skill/skill.yaml
name: your-skill-name
description: 简短描述这个技能能做什么
version: 0.1.0
author: your-name
# 触发条件(当用户输入匹配时激活)
triggers:
- keywords: ["发邮件", "send email"]
- intent: "send_email"
# 执行逻辑(支持多种类型)
execution:
type: shell # 或: python, node, http, llm-task
command: ./send_email.sh # 或 script.py / API 端点
# 输入参数定义
inputs:
- name: recipient
type: string
required: true
description: "收件人邮箱"
- name: subject
type: string
required: false
# 输出格式(供后续技能或对话使用)
outputs:
- name: status
type: string
- name: message_id
type: string
# 权限与安全(重要!)
permissions:
- network: true # 是否需要联网
- filesystem: read # 文件读取权限
- env_vars: ["EMAIL_API_KEY"] # 需要的环境变量
# 依赖项
dependencies:
- python-packages: ["requests", "smtplib"]
- system-tools: ["curl", "jq"]
二、3 种常见 Skills 写法示例
示例 1:命令行工具封装(最简单)
# skills/weather-check/skill.yaml
name: weather-check
description: 查询指定城市的天气
triggers:
- keywords: ["天气", "气温", "weather"]
execution:
type: shell
command: curl -s "https://www.landui.com/{city}?format=3"
inputs:
- name: city
type: string
required: true
description: "城市名称,如 Beijing"
outputs:
- name: result
type: string
permissions:
- network: true
使用方式:用户说”北京天气怎么样” → OpenClaw 自动调用此 Skill → 返回结果
示例 2:Python 脚本技能(复杂逻辑)
# skills/pdf-summarize/skill.yaml
name: pdf-summarize
description: 读取 PDF 文件并用 AI 生成摘要
triggers:
- keywords: ["总结这个PDF", "summarize pdf"]
execution:
type: python
script: |
import fitz, openclaw
def run(file_path: str, model: str = "qwen-plus"):
# 1. 提取 PDF 文本
doc = fitz.open(file_path)
text = "\\n".join([page.get_text() for page in doc])
# 2. 调用 LLM 摘要
summary = openclaw.llm.summarize(text, model=model)
return {"summary": summary, "pages": len(doc)}
inputs:
- name: file_path
type: string
required: true
- name: model
type: string
default: "qwen-plus"
outputs:
- name: summary
type: string
- name: pages
type: integer
dependencies:
- python-packages: ["PyMuPDF", "openclaw-sdk"]
permissions:
- filesystem: read
- llm-access: true
示例 3:HTTP API 集成技能
# skills/github-pr-check/skill.yaml
name: github-pr-check
description: 检查 GitHub PR 状态并通知
triggers:
- keywords: ["PR状态", "pull request"]
execution:
type: http
url: "https://www.landui.com/repos/{owner}/{repo}/pulls/{pr_number}"
method: GET
headers:
Authorization: "Bearer ${GITHUB_TOKEN}"
Accept: "application/vnd.github+json"
inputs:
- name: owner
type: string
required: true
- name: repo
type: string
required: true
- name: pr_number
type: integer
required: true
outputs:
- name: status
type: string # open/closed/merged
- name: title
type: string
permissions:
- network: true
- env_vars: ["GITHUB_TOKEN"]
三、Skills 安装与管理
安装方式
# 方式1:ClawHub CLI(推荐)
clawhub install <skill-slug>
# 例:clawhub install steipete/slack
# 方式2:手动安装
# 复制技能文件夹到:
~/.openclaw/skills/ # 全局
<项目目录>/skills/ # 项目级(优先级更高)
# 方式3:聊天中直接安装
# 在 OpenClaw 对话中粘贴 GitHub 链接,让 AI 自动安装
查看已安装 Skills
openclaw skills list
openclaw skills info <skill-name>
夜雨聆风