diff --git a/src/chat/chatter_manager.py b/src/chat/chatter_manager.py index c906fd901..be70f4969 100644 --- a/src/chat/chatter_manager.py +++ b/src/chat/chatter_manager.py @@ -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) diff --git a/src/chat/message_receive/chat_stream.py b/src/chat/message_receive/chat_stream.py index 1e15eef68..82187415f 100644 --- a/src/chat/message_receive/chat_stream.py +++ b/src/chat/message_receive/chat_stream.py @@ -257,6 +257,10 @@ class ChatStream: self.last_interaction_time = time.time() self.focus_energy = self._calculate_dynamic_focus_energy() + def update_focus_energy(self): + """手动触发更新focus_energy""" + self.focus_energy = self._calculate_dynamic_focus_energy() + def record_action(self, is_reply: bool = False): """记录动作执行""" self.action_count += 1 diff --git a/src/plugins/built_in/affinity_flow_chatter/planner.py b/src/plugins/built_in/affinity_flow_chatter/planner.py index b3b86210c..cc05213f1 100644 --- a/src/plugins/built_in/affinity_flow_chatter/planner.py +++ b/src/plugins/built_in/affinity_flow_chatter/planner.py @@ -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 # 检查兴趣度是否达到非回复动作阈值