TRPG Session Framework
Run tabletop RPGs through OpenClaw's multi-agent system — a DM agent narrates and adjudicates,
PC agents roleplay with distinct personalities, and human players join the same Discord channel.
Architecture Overview
CODEBLOCK0
Key principle: each agent has its own workspace, SOUL.md (personality), and memory scope.
Rules/lore are shared via reference files or vector DB; character secrets stay private.
Setup Workflow
1. Choose a System
Determine the rule system (D&D 5e, Call of Cthulhu, Fate, homebrew, etc.).
This affects which reference files to create. See references/systems.md for supported presets.
2. Create the Campaign Workspace
CODEBLOCK1
- -
rules/ — indexed rulebook excerpts (core mechanics, spells, items) - INLINECODE2 — world setting, maps, factions, NPCs
- INLINECODE3 — one .md per PC/NPC with stats, backstory, bonds
- INLINECODE4 — auto-generated session logs
3. Create Agents
DM Agent
Create via OpenClaw config. Minimal agent definition:
CODEBLOCK2
PC Agent (per AI character)
CODEBLOCK3
4. Write Character Files
Each character gets a .md file in characters/:
CODEBLOCK4
5. Index Rules
Convert rulebook excerpts into structured .md files under rules/.
Keep each file focused: rules/combat.md, rules/magic.md, rules/skills.md, etc.
For large rule sets, prefer a vector DB plugin (lancedb-pro) for semantic retrieval.
For smaller/homebrew games, .md references with clear headers are sufficient.
6. Configure the Discord Channel
- - Create a dedicated channel (e.g.,
#campaign-name) - Add all agents (DM + PCs) to that channel via triggers
- Set
mentionOnly: true so agents only respond when @mentioned - Human players just talk normally; @DM to take actions
7. Session Management
Starting a Session
DM opens with a scene-setting message. The DM agent should:
- 1. Read the latest session log for continuity
- Summarize "last time on..." if resuming
- Set the scene
During Play
- - Players (human or AI) describe actions
- @DM to request dice rolls or adjudication
- DM agent rolls dice using format: INLINECODE13
- DM tracks initiative in pinned message when in combat
Ending a Session
Tell the DM: "End session." The DM agent should:
- 1. Write a session summary to INLINECODE14
- Update character states (HP, inventory, conditions)
- Note any plot threads for next session
Dice Rolling
DM agent uses pseudo-random dice. Format:
CODEBLOCK5
Implement via simple random generation in the DM's system prompt instructions,
or use a scripts/roll.sh helper for verifiable randomness.
Memory Architecture
| Layer | Mechanism | Scope |
|---|
| Long-term | Vector DB (lancedb-pro) or indexed .md files | Rules, lore, backstories |
| Medium-term |
Session logs in
sessions/ | Campaign continuity |
|
Short-term | Agent memory scope + LCM | Current session context |
|
Private | Per-agent memory scope | Character secrets, hidden motives |
Reference Files
- -
references/systems.md — Rule system presets and quick-start configs - INLINECODE18 — DM agent behavior guidelines and narrative techniques
- INLINECODE19 — Template for session log files
Quick Start Checklist
- 1. [ ] Decide campaign name, rule system, and setting
- [ ] Create campaign workspace directory structure
- [ ] Write or import rule reference files
- [ ] Write lore/setting files
- [ ] Create character sheets for AI PCs
- [ ] Write SOUL.md files for DM and each PC
- [ ] Add agent configs to OpenClaw
- [ ] Create Discord channel and configure triggers
- [ ] Run a test scene to verify all agents respond correctly
- [ ] Start Session 1!
TRPG会话框架
通过OpenClaw的多智能体系统运行桌面角色扮演游戏——一个DM智能体负责叙述和裁决,PC智能体以独特的个性进行角色扮演,人类玩家可以加入同一个Discord频道。
架构概览
Discord频道 (#战役名称)
├── @DM智能体 — 叙述、NPC、规则、骰子
├── @PC-智能体A — 拥有独立个性和记忆的AI角色
├── @PC-智能体B — 拥有独立个性和记忆的AI角色
└── 人类玩家 — 自由输入,@DM进行行动
关键原则: 每个智能体都有自己的工作空间、SOUL.md(个性)和记忆范围。
规则/背景通过参考文件或向量数据库共享;角色秘密保持私密。
设置工作流程
1. 选择系统
确定规则系统(D&D 5e、克苏鲁的呼唤、命运、自创规则等)。
这会影响需要创建哪些参考文件。参见 references/systems.md 了解支持的预设。
2. 创建战役工作空间
bash
mkdir -p ~/.openclaw/trpg/<战役缩写>/{rules,lore,characters,sessions}
- - rules/ — 索引化的规则书摘录(核心机制、法术、物品)
- lore/ — 世界设定、地图、派系、NPC
- characters/ — 每个PC/NPC一个.md文件,包含属性、背景故事、羁绊
- sessions/ — 自动生成的会话日志
3. 创建智能体
DM智能体
通过OpenClaw配置创建。最小智能体定义:
yaml
在openclaw配置的agents部分
dm-<战役缩写>:
model: anthropic/claude-sonnet-4-6 # 或首选模型
systemPrompt: |
你是战役<战役名称>的地下城主。
系统:<规则系统>
你的职责:
- 生动但简洁地叙述场景
- 以鲜明的个性为所有NPC配音
- 公平裁决规则;必要时掷骰子
- 追踪先攻、生命值、状态
- 未经许可不得为玩家角色行动
阅读你的SOUL.md和战役文件了解世界详情。
soul: ~/.openclaw/trpg/<战役缩写>/dm-soul.md
workspace: ~/.openclaw/trpg/<战役缩写>
memory:
scope: agent:dm-<战役缩写>
triggers:
- pattern: .*
channels: [discord:#<战役频道>]
mentionOnly: true
PC智能体(每个AI角色)
yaml
pc-<角色名称>:
model: anthropic/claude-haiku-4-5 # PC使用较轻量模型即可
systemPrompt: |
你是<角色名称>,战役<战役名称>中的<种族><职业>。
保持角色身份。以你的角色身份回应DM和其他玩家。
你可以描述行动、对话和内心想法。
不要掷骰子或裁决规则——那是DM的工作。
阅读你的角色卡和SOUL.md了解个性详情。
soul: ~/.openclaw/trpg/<战役缩写>/characters/<角色名称>-soul.md
workspace: ~/.openclaw/trpg/<战役缩写>
memory:
scope: agent:pc-<角色名称>
triggers:
- pattern: .*
channels: [discord:#<战役频道>]
mentionOnly: true
4. 编写角色文件
每个角色在 characters/ 中获得一个 .md 文件:
markdown
<角色名称>
基本信息
- - 种族: 人类
- 职业: 法师(3级)
- 背景: 学者
- 阵营: 中立善良
属性
生命值/护甲等级/速度
- - 生命值:18 / 最大:18
- 护甲等级:12(法师护甲:15)
- 速度:30英尺
个性
- - 特质: 好奇、书卷气、心不在焉
- 羁绊: 寻找失踪的导师
- 缺陷: 对魔法解决方案过于自信
背景故事
(2-3段)
物品栏
法术
(列出已准备的法术)
5. 索引规则
将规则书摘录转换为 rules/ 下的结构化.md文件。
保持每个文件聚焦:rules/combat.md、rules/magic.md、rules/skills.md 等。
对于大型规则集,建议使用向量数据库插件(lancedb-pro)进行语义检索。
对于小型/自创规则游戏,带有清晰标题的.md参考文件就足够了。
6. 配置Discord频道
- - 创建一个专用频道(例如 #战役名称)
- 通过触发器将所有智能体(DM + PC)添加到该频道
- 设置 mentionOnly: true,使智能体仅在@提及时才响应
- 人类玩家正常说话;@DM进行行动
7. 会话管理
开始会话
DM以场景设定消息开场。DM智能体应:
- 1. 读取最新的会话日志以保持连续性
- 如果继续之前的内容,总结上一期...
- 设定场景
游戏过程中
- - 玩家(人类或AI)描述行动
- @DM请求掷骰子或裁决
- DM智能体使用格式掷骰子:🎲 d20 + 5 = [掷骰结果] + 5 = 总计
- DM在战斗中通过置顶消息追踪先攻顺序
结束会话
告诉DM:结束会话。DM智能体应:
- 1. 将会话摘要写入 sessions/session-NNN.md
- 更新角色状态(生命值、物品栏、状态)
- 记录下次会话的剧情线索
掷骰子
DM智能体使用伪随机骰子。格式:
🎲 <骰子>:[结果] → 总计(情境)
🎲 d20+5:[14] + 5 = 19(运动检定)
🎲 2d6+3:[4, 2] + 3 = 9(巨剑伤害)
通过DM系统提示指令中的简单随机生成实现,
或使用 scripts/roll.sh 辅助工具实现可验证的随机性。
记忆架构
| 层级 | 机制 | 范围 |
|---|
| 长期记忆 | 向量数据库(lancedb-pro)或索引化的.md文件 | 规则、背景、背景故事 |
| 中期记忆 |
sessions/ 中的会话日志 | 战役连续性 |
|
短期记忆 | 智能体记忆范围 + LCM | 当前会话上下文 |
|
私密记忆 | 每个智能体的记忆范围 | 角色秘密、隐藏动机 |
参考文件
- - references/systems.md — 规则系统预设和快速启动配置
- references/dm-guide.md — DM智能体行为指南和叙述技巧
- references/session-template.md — 会话日志文件模板
快速启动清单
- 1. [ ] 决定战役名称、规则系统和设定
- [ ] 创建战役工作空间目录结构
- [ ] 编写或导入规则参考文件
- [ ] 编写背景/设定文件
- [ ] 为AI PC创建角色卡
- [ ] 为DM和每个PC编写SOUL.md文件
- [ ] 将智能体配置添加到OpenClaw
- [ ] 创建Discord频道并配置触发器
- [ ] 运行测试场景,验证所有智能体正确响应
- [ ] 开始第一场会话!