feat(chat): 实现 focus_energy 的实时更新与同步机制
为了解决 `focus_energy` 更新不及时,导致其无法准确反映当前对话兴趣度的问题,本次提交引入了一套新的实时更新与同步机制。 这确保了每当消息的兴趣度发生变化时,代表机器人注意力的 `focus_energy` 也能被立即重新计算和更新,使决策更加精准。 主要变更: 1. **手动更新**: 在 `ChatStream` 中新增 `update_focus_energy` 方法,允许外部逻辑在需要时手动触发 `focus_energy` 的重新计算。 2. **实时计算**: `ChatterActionPlanner` 在评估并更新消息兴趣度后,会立即调用 `update_focus_energy`,确保了兴趣度到注意力的即时传导。 3. **状态同步**: `ChatterManager` 在完成一次执行后,会主动将 `mood_manager` 中可能已更新的 `chat_stream` 同步回当前的 `StreamContext`,保证了整个处理流中数据的一致性。
This commit is contained in:
@@ -107,6 +107,16 @@ class ChatterManager:
|
||||
result = await self.instances[stream_id].execute(context)
|
||||
self.stats["successful_executions"] += 1
|
||||
|
||||
# 从 mood_manager 获取最新的 chat_stream 并同步回 StreamContext
|
||||
try:
|
||||
from src.mood.mood_manager import mood_manager
|
||||
mood = mood_manager.get_mood_by_chat_id(stream_id)
|
||||
if mood and mood.chat_stream:
|
||||
context.chat_stream = mood.chat_stream
|
||||
logger.debug(f"已将最新的 chat_stream 同步回流 {stream_id} 的 StreamContext")
|
||||
except Exception as sync_e:
|
||||
logger.error(f"同步 chat_stream 回 StreamContext 失败: {sync_e}")
|
||||
|
||||
# 记录处理结果
|
||||
success = result.get("success", False)
|
||||
actions_count = result.get("actions_count", 0)
|
||||
|
||||
Reference in New Issue
Block a user