
第8讲:OpenClaw 平台深度解析
掌握开源 Skill 平台 OpenClaw,实现更灵活的 Skill 开发。
一、OpenClaw 简介
1.1 什么是 OpenClaw?
OpenClaw 是一个开源的 AI Skill 开发平台:
- ✅ 完全开源,代码可控
- ✅ Python 原生支持
- ✅ 本地运行,数据安全
- ✅ 丰富的 ClawHub 生态
1.2 与 Coze 的区别
| 特性 | Coze | OpenClaw |
|---|
| 部署方式 | 云端 | 本地/云端 |
| 代码控制 | 受限 | 完全控制 |
| 数据安全 | 云端存储 | 本地存储 |
| 开发方式 | 可视化+代码 | 纯代码 |
| 生态规模 | 大 | 中等 |
二、环境搭建
2.1 安装 OpenClaw
1 2 3 4 5 6 7
| pip install openclaw
git clone https://github.com/openclaw/openclaw.git cd openclaw pip install -e .
|
2.2 初始化项目
1 2 3 4 5 6 7 8 9 10 11 12
| openclaw init my-skill
cd my-skill
my-skill/ ├── skill.yaml ├── main.py ├── requirements.txt └── tests/
|
2.3 配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| name: excel-merge-skill description: 合并 Excel 文件的 Skill version: 1.0.0 author: your-name
entry: main.py
intents: - name: merge_excel description: 合并多个 Excel 文件 parameters: - name: files type: array required: true - name: mode type: string enum: [vertical, horizontal] default: vertical
|
三、开发第一个 OpenClaw Skill
3.1 主程序结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| from openclaw import Skill, Intent import pandas as pd
class ExcelMergeSkill(Skill): """Excel 合并 Skill""" def __init__(self): super().__init__() self.register_intent("merge_excel", self.merge_excel) def merge_excel(self, files, mode="vertical"): """合并 Excel 文件""" dfs = [pd.read_excel(f) for f in files] if mode == "vertical": result = pd.concat(dfs, ignore_index=True) else: result = pd.concat(dfs, axis=1) output_path = "merged.xlsx" result.to_excel(output_path, index=False) return { "success": True, "file": output_path, "rows": len(result) }
if __name__ == "__main__": skill = ExcelMergeSkill() skill.run()
|
3.2 运行 Skill
1 2 3 4 5 6 7 8
| openclaw run
openclaw run --debug
openclaw run --port 8080
|
四、ClawHub 生态
4.1 什么是 ClawHub?
ClawHub 是 OpenClaw 的 Skill 市场:
- 1700+ 开源 Skills
- 覆盖各种办公场景
- 可直接安装使用
4.2 使用 ClawHub
1 2 3 4 5 6 7 8 9 10 11
| openclaw search excel
openclaw install excel-processor
openclaw list
openclaw update excel-processor
|
4.3 发布到 ClawHub
1 2 3 4 5
| openclaw package
openclaw publish
|
五、高级功能
5.1 自定义工具
1 2 3 4 5 6 7 8 9 10 11 12 13
| from openclaw import Tool
class ExcelTool(Tool): """自定义 Excel 工具""" def read(self, file_path): return pd.read_excel(file_path) def merge(self, files, mode): dfs = [self.read(f) for f in files] if mode == "vertical": return pd.concat(dfs, ignore_index=True) return pd.concat(dfs, axis=1)
|
5.2 多轮对话
1 2 3 4 5 6 7 8 9 10 11 12
| def handle_conversation(self, user_input, context): """处理多轮对话""" if context.get("step") == "waiting_files": context["files"] = user_input context["step"] = "waiting_mode" return "请选择合并方式:1.按行 2.按列" elif context.get("step") == "waiting_mode": mode = "vertical" if user_input == "1" else "horizontal" return self.merge_excel(context["files"], mode)
|
六、下节预告
第9讲:OpenClaw 实战:开发数据处理 Skill
我们将:
- 开发一个完整的数据处理 Skill
- 集成 Python 数据分析库
- 发布到 ClawHub
加入学习群
OpenClaw 使用有疑问?欢迎加入交流群:
👉 加入AI编程学习交流群

本讲是《Skills 从入门到实践》系列课程的第8讲。
🎓 AI 编程实战课程
想系统学习 AI 编程?程序员晚枫的 AI 编程实战课 帮你从零上手!