From dcb78cd9b844d6b8cca585ae2aae7a76f4f333fc Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Sun, 31 Aug 2025 13:45:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E5=9C=A8=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E6=80=9D=E8=80=83=E6=97=B6=E9=BB=98=E8=AE=A4=E9=80=89=E5=8F=96?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=B6=88=E6=81=AF=E4=BD=9C=E4=B8=BA=E7=9B=AE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当主动思考的 `target_message` 为 `None` 时,系统现在会自动获取聊天流中的最新一条消息作为默认的目标消息。 这确保了即使在没有明确指定目标消息的情况下,主动思考也能够针对最近的上下文执行动作,从而提高了交互的连续性和相关性。 --- src/chat/chat_loop/proactive_thinker.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/chat/chat_loop/proactive_thinker.py b/src/chat/chat_loop/proactive_thinker.py index 69fec753d..6f6aacef4 100644 --- a/src/chat/chat_loop/proactive_thinker.py +++ b/src/chat/chat_loop/proactive_thinker.py @@ -271,6 +271,20 @@ class ProactiveThinker: # 如果决策不是 do_nothing,则执行 if action_result and action_result.get("action_type") != "do_nothing": logger.info(f"{self.context.log_prefix} 主动思考决策: {action_result.get('action_type')}, 原因: {action_result.get('reasoning')}") + # 在主动思考时,如果 target_message 为 None,则默认选取最新 message 作为 target_message + if target_message is None and self.context.chat_stream and self.context.chat_stream.context: + from src.chat.message_receive.message import MessageRecv + latest_message = self.context.chat_stream.context.get_last_message() + if isinstance(latest_message, MessageRecv): + user_info = latest_message.message_info.user_info + target_message = { + "chat_info_platform": latest_message.message_info.platform, + "user_platform": user_info.platform if user_info else None, + "user_id": user_info.user_id if user_info else None, + "processed_plain_text": latest_message.processed_plain_text, + "is_mentioned": latest_message.is_mentioned, + } + # 将决策结果交给 cycle_processor 的后续流程处理 await self.cycle_processor.execute_plan(action_result, target_message) else: