Skip to content

Plot 数据模型

字数
735 字
阅读时间
4 分钟

定义剧情图系统的核心数据结构:节点、选择、边。

PlotNode

剧情节点,代表故事中的一个关键时刻。每个节点捕获该时刻的完整上下文快照。

python
from nbot.plot import PlotNode

node = PlotNode(
    conversation_id="conv_abc",
    character_id="char_xyz",
    title="初次相遇",
    summary="在公园里偶遇了角色",
    level="important",
    scene={"location": "公园", "time": "傍晚"},
)

核心字段

字段类型说明
idstr自动生成,前缀 pn_
conversation_idstr所属会话
character_idstr关联角色
titlestr节点标题
summarystr剧情摘要
levelstr重要性:normal / important / turning_point / ending
created_atstrISO 时间戳,自动生成

场景与快照

字段类型说明
scenedict场景信息(地点、时间等)
state_snapshotdict角色状态快照(mood, energy)
relationship_snapshotdict关系状态快照(affection, trust, familiarity 等)

分支与消息

字段类型说明
parent_node_idstr父节点 ID(构建树形结构)
selected_choice_idstr已选择的选项 ID
user_messagedict用户消息快照(用于分支物化)
assistant_messagedict助手消息快照(含 idcontentaudio_url

v3.1 Activity Graph 扩展

字段类型说明
activity_typestr活动类型:chat / group / event / quest / ending
participantslist[str]参与者角色 ID 列表
locationstr场景地点
moodstr整体氛围
world_changesdict世界状态变化记录
memory_refslist[str]关联记忆 ID
review_scoredict[str, float]Review 评分快照

序列化

python
# 转为字典
data = node.to_dict()

# 从字典恢复
node = PlotNode.from_dict(data)

PlotChoice

玩家在某个节点可做的剧情选择。每个节点最多有 3 个未选中的选择。

python
from nbot.plot import PlotChoice

choice = PlotChoice(
    node_id="pn_abc",
    text="轻轻握住她的手",
    level="important",
    intent="推进关系",
)

字段

字段类型说明
idstr自动生成,前缀 pc_
node_idstr所属节点 ID
textstr选择文本(第一人称可直接发送的消息)
levelstrnormal / important / turning_point / ending / hidden
intentstr选择意图描述
selectedbool是否已被选择
created_atstrISO 时间戳

v3.1 扩展

字段类型说明
riskstr风险等级:low / medium / high
expected_effectdict预期效果(relationship, world, plot)
hidden_requirementsdict隐藏条件,如 {"affection_gte": 80, "trust_gte": 60}

PlotEdge

连接两个节点的边,表示某个选择导致的剧情走向。

字段类型说明
idstr自动生成,前缀 pe_
from_node_idstr起始节点
to_node_idstr目标节点
choice_idstr关联的选择 ID
labelstr边标签(通常为选择文本)

数据关系

PlotNode (pn_001)
  ├── PlotChoice (pc_001, selected=true)
  │     └── PlotEdge (pe_001, pn_001 → pn_002)
  ├── PlotChoice (pc_002, selected=false)
  └── PlotChoice (pc_003, selected=false)

PlotNode (pn_002)
  ├── PlotChoice (pc_004, selected=false)
  └── ...

一个节点可以有多个子分支(通过不同 choice 连接到不同子节点),形成树状剧情图。

页面历史