OpenClaw 核心概念详解:Session、Agent、Skill
摘要:深入理解 OpenClaw 的三大核心概念,掌握 Session 会话管理、Agent 智能体架构、Skill 技能系统,为高级开发打下坚实基础。
一、OpenClaw 架构概览
1.1 整体架构设计
OpenClaw 采用分层架构设计,从用户交互到 AI 模型调用,每一层都有明确的职责边界。理解这个架构是掌握 OpenClaw 的关键第一步。

1.2 三大核心概念
|
|
|
|
|
|---|---|---|---|
| Session |
|
|
|
| Agent |
|
|
|
| Skill |
|
|
|
二、Session 会话管理
2.1 什么是 Session?
Session(会话) 是 OpenClaw 中管理对话上下文的核心单元。每个 Session 包含对话历史、用户信息、会话状态和记忆数据。
2.2 Session 生命周期

2.3 Session 类型
|
|
|
|
|---|---|---|
| DM(直接消息) |
|
|
| Group(群聊) |
|
|
| Thread(线程) |
|
|
2.4 Session 配置
{"sessions": {"maxContextTokens": 4000,"autoResetThreshold": 0.8,"timeout": 3600,"memory": {"enabled": true,"type": "semantic"}}}
2.5 Session 常用操作
# 查看所有会话openclaw sessions list# 查看特定会话详情openclaw sessions show <session-id># 重置会话(清除上下文)openclaw sessions reset <session-id># 删除会话openclaw sessions delete <session-id>
三、Agent 智能体
3.1 什么是 Agent?
Agent(智能体) 是 OpenClaw 的”大脑”,负责理解用户意图、规划执行步骤、调用工具、生成响应。
3.2 Agent 架构

3.3 Agent 类型
|
|
|
|
|---|---|---|
| Main Agent |
|
|
| Subagent |
|
|
| ACP Agent |
|
|
3.4 Agent 配置
{"agents": {"main": {"model": "gpt-4o-mini","thinking": "medium","maxTokens": 4000}}}
3.5 Thinking 模式
|
|
|
|
|---|---|---|
off |
|
|
low |
|
|
medium |
|
|
high |
|
|
四、Skill 技能系统
4.1 什么是 Skill?
Skill(技能) 是 OpenClaw 的能力扩展单元,封装了特定领域的知识和工具。
4.2 Skill 目录结构
skills/└── my-skill/├── SKILL.md # 技能说明(必需)├── scripts/ # 脚本文件└── references/ # 参考文档
4.3 Skill 触发机制

4.4 Skill 类型
|
|
|
|
|---|---|---|
| 内置技能 |
|
|
| 自定义技能 |
|
|
| ClawHub 技能 |
|
|
4.5 安装和管理技能
# 从 ClawHub 安装技能npx clawhub@latest install <skill-name># 查看已安装技能openclaw skills list
五、三者关系
5.1 协作流程

5.2 数据流向
|
|
|
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
六、实战案例
6.1 创建自定义 Skill
# 创建技能目录mkdir -p ~/.openclaw/workspace/skills/hello-world# 创建技能说明文件cat > ~/.openclaw/workspace/skills/hello-world/SKILL.md << 'EOF'---name: hello-worlddescription: "简单的问候技能。触发词:你好、hello"---# Hello World 技能当用户打招呼时,友好地回应。## 功能- 识别问候语- 返回友好回复EOF
6.2 配置 Session 记忆
{"sessions": {"memory": {"enabled": true,"longTerm": {"file": "MEMORY.md"},"daily": {"dir": "memory"}}}}
七、常见问题
Q1: Session 和 Agent 有什么区别?
Session 管理对话上下文,Agent 处理业务逻辑。Session 是”容器”,Agent 是”处理器”。
Q2: 如何选择 Thinking 模式?
|
|
|
|---|---|
|
|
off |
|
|
low |
|
|
medium |
|
|
high |
Q3: Skill 和 Tool 有什么区别?
Skill 是完整的技能包,包含说明、脚本、参考文档。Tool 是单个工具函数,是 Skill 的组成部分。
八、总结
核心要点
|
|
|
|
|---|---|---|
| Session |
|
maxContextTokens
timeout |
| Agent |
|
model
thinking |
| Skill |
|
SKILL.md
scripts/ |
学习路径

参考资料:
-
OpenClaw 官方文档:https://docs.openclaw.ai -
ClawHub 技能市场:https://clawhub.com -
GitHub 仓库:https://github.com/openclaw/openclaw
夜雨聆风