以 OpenClaw Skills 机制为例:把一次性提示变成可复用能力
第九课
郑思尧
上海交通大学 国际与公共事务学院
大纲标题是“大语言模型”。所以开头先讲 LLM 的技术底座: token、Transformer、上下文、训练、推理与幻觉风险。 后半段再进入 OpenClaw Skills:如何把 LLM 能力写成可复用、可审计的研究流程。
因此,模型越像“懂了”,越需要问:它的判断来自上下文证据、训练中学到的模式,还是一次流畅的概率补全?
Self-attention 让每个 token 在生成表示时“看向”上下文中相关的 token。 这使模型可以处理指代、长距离依赖、格式模仿和多步文本结构。
社科研究中,LLM 输出必须绑定原始材料、证据摘录、处理脚本和审计记录;不能只保存“看起来合理”的最终答案。
LLM 提供语言与推理能力;工具让它读写、搜索、计算;Agent Loop 让它多步执行; Skill 则把反复使用的流程写成明确、可复验的操作规程。
SKILL.md<available_skills> 列表。
模型先只看到 name / description / location;真正需要使用时,再用 read 工具读取对应的 SKILL.md。
SKILL.md:元数据 + 指令skills/
interview-coding/
SKILL.md
templates/
codebook.md
scripts/
validate_labels.py
examples/
sample_interviews.csv
SKILL.md 的最小格式---
name: interview-coding
description: Code interview excerpts into a finite qualitative codebook.
---
# Interview Coding Skill
Use this when the user asks to classify interview excerpts,
open-ended survey responses, or field notes.
Workflow:
1. Verify input path, encoding, and row count.
2. Read or create a finite codebook.
3. Label each excerpt with code, confidence, and evidence quote.
4. Save outputs as CSV and Markdown audit report.
OpenClaw 遵循 AgentSkills 兼容目录;frontmatter 的 key 需要保持单行,metadata 也建议写成单行 JSON。
<available_skills>
<skill>
<name>interview-coding</name>
<description>Code interview excerpts...</description>
<location>/workspace/skills/interview-coding/SKILL.md</location>
</skill>
</available_skills>
| 位置 | 作用 | 优先级 |
|---|---|---|
<workspace>/skills |
当前 agent / 当前课堂项目专用 skill | 最高 |
~/.openclaw/skills |
本机共享、可管理、可覆盖 bundled 的 skill | 中 |
| bundled skills | OpenClaw 安装包或 OpenClaw.app 自带 | 最低 |
skills.load.extraDirs |
额外共享 skill 包目录 | 最低扩展层 |
同名冲突时:workspace wins。课堂实验优先把自定义 skill 放进当前 workspace。
os:只在 darwin / linux / win32 中某些平台启用requires.bins:要求命令在 host 的 PATH 上存在requires.anyBins:多个命令至少存在一个requires.env:要求环境变量或配置提供requires.config:要求 openclaw.json 中某项为真---
name: policy-crawler
description: Crawl policy pages into auditable CSV.
metadata: {"openclaw":{"requires":{"bins":["python3"],"env":["TAVILY_API_KEY"]},"primaryEnv":"TAVILY_API_KEY"}}
---
注意:requires.bins 检查的是 host;如果实际运行在 Docker sandbox,容器里也必须有这个命令。
openclaw.json:skills 的控制面{
skills: {
allowBundled: ["gemini", "peekaboo"],
load: {
extraDirs: ["~/Projects/course-skills"],
watch: true,
watchDebounceMs: 250
},
install: {
preferBrew: true,
nodeManager: "npm"
},
entries: {
"policy-crawler": {
enabled: true,
apiKey: { source: "env", provider: "default", id: "TAVILY_API_KEY" },
config: { maxPages: 30 }
},
sag: { enabled: false }
}
}
}
entries.env 或 apiKey。
沙箱会话里,skill 进程在 Docker 内运行;sandbox 不继承 host process.env。需要用 sandbox docker env 或自定义镜像。
默认情况下,会话开始时记录 eligible skills;改动 skill 或配置后,通常新会话生效。
如果 watcher 开启,SKILL.md 改动会刷新 snapshot,下一轮 agent turn 可拾取。
{ skills: { load: { watch: true, watchDebounceMs: 250 } } }
openclaw.plugin.json 里声明 skills 目录。
插件启用后,其 skills 参与正常优先级规则。
clawhub install <skill-slug>
clawhub update --all
clawhub sync --all
不要把 OpenClaw 的 skill discovery 与 OpenAI 模型文档中的 “supported tools: skills” 混为一谈;前者是 OpenClaw 的运行时机制,后者是模型/平台工具能力。
| 模型 | 官方定位(2026-04) | 适合放在哪类 Skill 后面 | 课堂提醒 |
|---|---|---|---|
gpt-5.5 |
最新 frontier reasoning model;面向复杂专业工作 | 工具密集、多步分析、长文档综合、复杂代码执行 | 默认 reasoning.effort=medium,复杂任务再升高 |
gpt-5.4 |
frontier model;更偏可负担的专业工作 | 常规研究助理、代码分析、文档处理、批量工作流 | 支持 none/low/medium/high/xhigh |
gpt-5.1 |
coding / agentic tasks 的旗舰模型 | 较稳定的编码、工具调用、agent 任务 | 可作为课程演示里的强基线 |
gpt-5 |
上一代 reasoning / coding / agentic model | 兼容旧 workflow 或复现实验设置 | 新项目优先评估更新模型 |
注:模型名与可用性会变化;正式部署前以当前 provider / OpenAI API 文档为准。
原则:不要因为模型“更会想”就盲目拉高 effort。先用代表性样例做 eval;只有质量收益超过成本和延迟,才提高推理档位。
# Model policy
Default:
- Use a fast/low-effort model for schema checks, deduplication, and simple labeling.
Escalate:
- Use a stronger reasoning model when:
1. codebook definitions conflict,
2. confidence is low on more than 20% of rows,
3. the task requires tool-heavy multi-step execution.
Do not:
- Change model silently after producing results.
- Hide cost/latency tradeoffs from the user.
- Treat model output as validated evidence without spot-checks.
好的 skill 写“模型选择规则”,不把某个模型神化为答案。研究流程要能换模型、能复验、能解释差异。
---
name: open-response-coding
description: Classify Chinese open-ended survey answers with a finite codebook and audit trail.
---
# Open Response Coding
Use when the user provides CSV/XLSX/text responses and asks for coding,
categorization, or qualitative labeling.
Rules:
- Verify file path, encoding, row count, and target column before analysis.
- Do not invent unlimited categories; propose at most 6 codes first.
- For each row, output: id, code, confidence, evidence_quote.
- Save `coded_responses.csv` and `coding_report.md`.
- Randomly spot-check 10 rows and report disagreements or low confidence.
- If input contains direct identifiers, stop and ask for de-identification.
templates/codebook.md:固定输出结构scripts/validate_labels.py:检查标签、置信度、缺失值examples/sample.csv:给模型具体 I/O 参照{baseDir}:在说明中引用 skill 自身目录Before final answer:
1. Run:
python3 {baseDir}/scripts/validate_labels.py coded_responses.csv
2. Include validation output in the report.
3. If validation fails, repair the CSV instead of hiding the error.
openclaw agent --message "use open-response-coding on examples/sample.csv"SKILL.md,是否生成指定文件。
如果 skill 需要跑重任务或外部 API,先用小样本;不要把失败包装成“已完成”。
研究者负责解释与修订 codebook;skill 负责让流程可重复、可检查。
Output contract:
policy_list.csv columns:
source, title, date, agency, url, fetched_at, hash
skills/my-mini-skill/SKILL.md:name、description、触发条件、输出契约。提交标准:SKILL.md + sample input + output artifact + 你认为最需要人工复核的一点。
{baseDir}。
Skill 是 Agent 的
可复用研究规程
OpenClaw 用 SKILL.md 把能力边界、工具使用、输出契约和验证步骤写入系统。
好的 skill 不追求“更聪明”,而追求可复现、可审计、可修改、可共享。
Write the procedure once; make every run inspectable.
从"聊天"到"行动"——让 AI 替你动手
第九课
郑思尧
上海交通大学 国际与公共事务学院
目标:今天结束时,你能用 OpenClaw 让 AI 帮你自动完成一段文本分析任务——不只是"聊天",而是真正动手干活。
LLM 是"大脑",Agent 是"大脑 + 四肢"。OpenClaw 就是让 Claude 长出四肢的框架。
社科研究类比:LLM 是图书馆,Agent 是会使用图书馆、做实验、整理笔记的研究助理。
例:分析 100 条微博情感
Think: 我需要先读文件,再逐条分类
Act: read_file("weibo.csv")
Observe: 获得 100 行文本
Think: 用 LLM 批量打标签
Act: 调用模型 API…
Observe: 获得标签结果
Act: write_file("result.csv")
本课实验:交大 ailab 已为大家部署好 Gateway,你直接用 Web Chat 接入,背后是 GLM-5 / DeepSeek 等模型。
read 读文件(txt / csv / pdf / 代码)write 写文件、生成报告glob 批量查找文件~/.openclaw/workspace/
exec 在服务器上跑 Bash / Pythonweb_search 联网检索web_fetch 抓取网页内容每次重新打开实验环境,需要重新配置模型并获取令牌(约 2 分钟)。配置一次,当次有效。
ailab.sjtu.edu.cn,用 jAccount 登录
done 输出 = 配置成功
openclaw dashboard#token= 后面的字符串,复制
pairing required 错误?回 Web 终端执行:openclaw devices approvesjtu/glm-5 = 成功!
在 Chat 界面用 /model sjtu/模型名 切换
| 模型 | 调用名 | 特点 | 适合场景 |
|---|---|---|---|
| GLM 5.0 默认 | sjtu/glm-5 |
快速、中文强 | 日常对话、文本分析、Agent 任务 |
| DeepSeek Chat | sjtu/deepseek-chat |
推理能力强 | 复杂文本理解、摘要生成 |
| DeepSeek Reasoner 推理 | sjtu/deepseek-reasoner |
慢但深思熟虑 | 复杂逻辑推理、数据分析规划 |
| Qwen3 Coder | sjtu/qwen3coder |
代码能力最强 | 让 Agent 写分析脚本 |
| Qwen3 VL 视觉 | sjtu/qwen3vl |
理解图片 | 图表解读、截图分析 |
建议:一般任务用默认 GLM-5;需要 Agent 写代码时换 Qwen3 Coder;要推理复杂问题时试 DeepSeek Reasoner。
❌ pairing required — 回 Web 终端,执行 openclaw devices approve,再回网关点 Connect
❌ Agent 网关打开后空白 — 必须右键 → "在新标签页中打开",不能直接点
❌ 配置命令报错 — 确保完整复制了整条命令(从 python3 到最后的引号),分段粘贴容易出错
❌ 环境突然消失 — 右上角有倒计时,归零后容器回收。点"延时"可续至 2 小时
✅ 成功标志:Chat 界面顶部显示 sjtu/glm-5,发一条消息有回复
你的指令(Prompt)
关键技巧:上传文件
把文件放进 workspace:
Web 终端 → openclaw workspace 查看路径
或直接在 Chat 界面上传附件
❌ 模糊 Prompt(差)
✅ 具体 Prompt(好)
研究者的责任:用 Agent 提速,用人的判断保质。永远要问:这个结果我能解释吗?
注意:即使自托管,也不要把真实受访者姓名、身份证号等敏感 PII 直接放入对话。先脱敏,再分析。
带着你的研究问题思考:
1. 你手上有哪类数据?让 Agent 分析,你会怎么写第一条 Prompt?
2. Agent 给出了结果,你会怎么验证它是对的?
3. 如果 Agent 的分类和你的直觉不一样,你怎么决定听谁的?
4. 用 OpenClaw 试一下:上传一个小文件 → 让 Agent 做一件具体的事
Agent 是你的
研究助理
不是替代者
OpenClaw 让 AI 能读、写、算、搜——真正"动手"
你的工作:给出清晰目标 + 严格验证结果 + 负责解释
数据上交大,分析交 Agent,判断交你自己
The agent does the running, you do the thinking — 郑思尧 2026