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:
@@ -136,6 +136,14 @@ class ChatterActionPlanner:
|
||||
chat_mood = mood_manager.get_mood_by_chat_id(self.chat_id)
|
||||
await chat_mood.update_mood_by_message(latest_message, score)
|
||||
logger.debug(f"已更新聊天 {self.chat_id} 的情绪状态,兴趣度: {score:.3f}")
|
||||
elif latest_message:
|
||||
# 即使不更新情绪状态,也要更新ChatStream的兴趣度数据
|
||||
chat_mood = mood_manager.get_mood_by_chat_id(self.chat_id)
|
||||
if hasattr(chat_mood, 'chat_stream') and chat_mood.chat_stream:
|
||||
chat_mood.chat_stream.add_message_interest(score)
|
||||
# 在这里同步更新 focus_energy
|
||||
chat_mood.chat_stream.update_focus_energy()
|
||||
logger.debug(f"已更新聊天 {self.chat_id} 的ChatStream兴趣度和Focus Energy,分数: {score:.3f}")
|
||||
|
||||
# base_threshold = self.interest_scoring.reply_threshold
|
||||
# 检查兴趣度是否达到非回复动作阈值
|
||||
|
||||
Reference in New Issue
Block a user