Skip to content

Plot 桥接模块

字数
517 字
阅读时间
3 分钟

剧情图系统通过三个桥接模块将剧情事件自动同步到记忆、世界书和多媒体子系统。桥接在 select_choice 时触发。

PlotMemoryBridge - 记忆桥接

选择被标记后,根据级别自动写入角色记忆。

级别映射

选择级别记忆类型说明
normal不写入普通选择不产生记忆
importantrelationship关系相关记忆
turning_pointevent重要事件记忆
endinglong长期记忆

使用方式

python
from nbot.plot.memory_bridge import PlotMemoryBridge

bridge = PlotMemoryBridge.instance()
bridge.on_choice_selected(
    choice=choice,
    conversation_id="conv_abc",
    character_id="char_xyz",
    user_id="user_123",
    memory_service=memory_service,
)

内部调用 memory_service.save() 写入记忆,选择文本作为记忆内容。

PlotWorldBookBridge - 世界书桥接

当剧情到达转折点时,自动将事件写入世界书。

触发条件

turning_point 级别的选择触发。

写入参数

参数
优先级80
条目类型event
标签["plot", "turning_point"]
关键词从中文文本自动提取(2-4 字,最多 5 个)

关键词提取

使用正则 [一-鿿]{2,4} 从选择文本和意图中提取中文关键词。

使用方式

python
from nbot.plot.world_book_bridge import PlotWorldBookBridge

bridge = PlotWorldBookBridge.instance()
bridge.on_turning_point(
    choice=choice,
    conversation_id="conv_abc",
    character_id="char_xyz",
    book_id="wb_001",
    world_book_store=world_book_store,
)

MultimediaBridge - 多媒体桥接

根据选择级别触发不同的多媒体动作。

触发规则

选择级别表情包强度TTS场景描述剧情回顾
normal0.3---
important0.6---
turning_point0.9-
ending1.0-

使用方式

python
from nbot.plot.multimedia_bridge import MultimediaBridge

bridge = MultimediaBridge.instance()
actions = bridge.generate_actions(choice_level="turning_point", plot_nodes=nodes)
# 返回: [{"type": "sticker", ...}, {"type": "tts", ...}, {"type": "scene_description", ...}]

辅助方法

python
# 角色状态卡(姓名、心情、精力、场景、关系)
card = bridge.build_status_card(character_state, relationship_state, scene)

# 群聊布局(含发言指示器)
layout = bridge.build_group_layout(group_conversation, active_speaker)

桥接触发流程

select_choice("pc_001")

  ├── PlotMemoryBridge.on_choice_selected()
  │     └── memory_service.save(...)  (important+)

  ├── PlotWorldBookBridge.on_turning_point()
  │     └── world_book_store.add_entry(...)  (turning_point only)

  └── MultimediaBridge.generate_actions()
        ├── sticker (all levels)
        ├── tts (turning_point, ending)
        ├── scene_description (turning_point)
        └── story_recap (ending)

桥接操作均为非阻塞,失败不影响主流程(异常仅 _log.debug)。

页面历史