使用OpenClaw创建自定义AI技能
今天我体验了使用OpenClaw创建自定义AI技能的全过程。这不仅仅是一个简单的工具,而是一个完整的工作流,让我能够通过自然语言描述来扩展AI的能力。
背景
我需要一个功能:能够远程在我的Hexo博客上发布文章。具体需求包括:
- SSH连接到我的远程服务器(192.168.10.100)
- 创建新的Hexo博客文章
- 填充Markdown内容
- 验证格式是否正确
- 等待我确认后部署发布
创建过程
第一步:自然语言描述需求
我直接用中文描述了我的需求,包括服务器信息、操作步骤、触发关键词等细节。OpenClaw理解了我的需求后,主动读取了skill-creator skill的SKILL.md文件,了解创建技能的标准流程。
第二步:初始化Skill结构
OpenClaw使用了skill-creator skill提供的init_skill.py脚本,自动生成了skill的目录结构:
1 | python3 /path/to/init_skill.py hexo-blog-poster --path . --resources scripts |
生成的目录结构:
1 | hexo-blog-poster/ |
第三步:编写SKILL.md
根据我的需求,OpenClaw编写了SKILL.md文件,包含了:
- Frontmatter: YAML格式的元数据(name和description)
name: hexo-blog-posterdescription: 详细描述了skill的功能和触发条件
- Body: 具体的工作流程和命令参考
第四步:打包和安装
使用package_skill.py将skill打包成.skill文件(实际是一个zip文件),然后解压到OpenClaw的skills目录中完成安装。
1 | python3 package_skill.py hexo-blog-poster |
Skill说明文档
以下是最终生成的hexo-blog-poster skill的完整说明:
1 |
|
1 | # Hexo Blog Poster |
Actions:
- Summarize and update title field: Read the user-provided content, summarize it to create an appropriate article title, then update the
titlefield in the frontmatter - Populate content: Replace the
正文section with the user-provided Markdown content - Keep the
datefield as-is unless instructed to modify - If user provides tags, update the
tagsfield
Step 4: Format Validation
Before proceeding, review entire .md file and check for:
Code block issues:
- Unclosed ``` code blocks
- Mismatched code block syntax
Heading hierarchy issues:
- Inconsistent heading levels (e.g., content that should be
##is marked as####) - Skipped heading levels (e.g.,
#to###without##)
If issues found:
- Pause the workflow
- Report specific issues to user
- Wait for user confirmation to proceed or fix
If no issues: Continue to Step 5
Step 5: Deploy
- Return to
/blogdirectory - Execute:
./hexo.sh - Monitor output for git push messages
- If push completes without errors: Success
- If errors occur: Report to user
Commands Reference
SSH connection:
1 | ssh root@192.168.10.100 |
Create new post:
1 | cd /blog |
Deploy:
1 | cd /blog |
1 |
|
Runtime: agent=main
Host: DESKTOP-3VAHGJ7
Repo: /home/ws/.openclaw/workspace
OS: Linux 4.4.0-19041-Microsoft (x64)
Node: v22.22.1
Shell: bash
Channel: webchat
Capabilities: none
Thinking: low
Reasoning: off
**模型信息:**
- **当前使用模型**:zai/glm-4.7
- **默认模型**:zai/glm-4.7
- **模型提供商**:Z.AI(智谱AI)
## 技能设计原则
根据skill-creator的指导,OpenClaw在创建这个skill时遵循了以下原则:
1. **简洁性优先**:默认假设AI已经足够智能,只添加必要的上下文信息
2. **渐进式披露**:三级加载系统(metadata → SKILL.md → bundled resources)优化上下文窗口使用
3. **适当的自由度**:根据任务的脆弱性和可变性选择具体的指导程度
4. **模块化资源**:支持scripts/、references/、assets/三种可选资源目录
## 总结
这次体验让我深刻感受到OpenClaw的强大之处:
1. **自然语言驱动**:不需要写代码,用中文描述需求即可
2. **自动化流程**:从初始化到安装,全程自动化处理
3. **标准化规范**:遵循AgentSkills规范,确保skill质量和可维护性
4. **即时可用**:创建完成后立即可用,无需额外配置
通过这种方式,我可以快速创建各种自定义技能,让AI更好地服务于我的特定需求。这不仅仅是写代码,而是在编程AI的行为模式。