From 6ea3b2af2694fab2ec3e82af753276caebde6980 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 24 Sep 2025 01:59:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(affinity=5Fflow=5Fchatter):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=88=B3=E4=B8=80=E6=88=B3=E5=8A=A8=E4=BD=9C=E4=BB=A5?= =?UTF-8?q?=E6=9B=B4=E7=B2=BE=E5=87=86=E5=9C=B0=E5=9B=9E=E5=BA=94=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当LLM在执行 poke_user 动作时未指定 target_message_id,系统现在会主动在消息历史中寻找触发该动作的“戳一戳”通知,以实现更具上下文的回应。如果未找到对应的通知消息,则会回退到使用最新的消息作为目标。 此外,本次更新包含以下修复: - 修复了在计划过滤器中错误地引用 `self.available_actions` 的问题,现已更正为 `plan.available_actions`。 - 修复了 `ActionModifier` 中动作列表在多阶段过滤时未及时更新的问题,确保了动作筛选的准确性。 --- src/chat/planner_actions/action_modifier.py | 8 +++--- .../affinity_flow_chatter/plan_filter.py | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/chat/planner_actions/action_modifier.py b/src/chat/planner_actions/action_modifier.py index 9c2fcc112..d3e5a555f 100644 --- a/src/chat/planner_actions/action_modifier.py +++ b/src/chat/planner_actions/action_modifier.py @@ -125,7 +125,8 @@ class ActionModifier: # === 第二阶段:检查动作的关联类型 === chat_context = self.chat_stream.context - type_mismatched_actions = self._check_action_associated_types(all_actions, chat_context) + current_actions_s2 = self.action_manager.get_using_actions() + type_mismatched_actions = self._check_action_associated_types(current_actions_s2, chat_context) if type_mismatched_actions: removals_s2.extend(type_mismatched_actions) @@ -140,11 +141,12 @@ class ActionModifier: logger.debug(f"{self.log_prefix}开始激活类型判定阶段") # 获取当前使用的动作集(经过第一阶段处理) - current_using_actions = self.action_manager.get_using_actions() + # 在第三阶段开始前,再次获取最新的动作列表 + current_actions_s3 = self.action_manager.get_using_actions() # 获取因激活类型判定而需要移除的动作 removals_s3 = await self._get_deactivated_actions_by_type( - current_using_actions, + current_actions_s3, chat_content, ) diff --git a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py index 86ffe9b86..ff3f960ca 100644 --- a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py +++ b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py @@ -443,8 +443,16 @@ class ChatterPlanFilter: if target_message_id := action_data.get("target_message_id"): target_message_dict = self._find_message_by_id(target_message_id, message_id_list) else: - # 如果LLM没有指定target_message_id,我们就默认选择最新的一条消息 - target_message_dict = self._get_latest_message(message_id_list) + # 如果LLM没有指定target_message_id,进行特殊处理 + if action == "poke_user": + # 对于poke_user,尝试找到触发它的那条戳一戳消息 + target_message_dict = self._find_poke_notice(message_id_list) + if not target_message_dict: + # 如果找不到,再使用最新消息作为兜底 + target_message_dict = self._get_latest_message(message_id_list) + else: + # 其他动作,默认选择最新的一条消息 + target_message_dict = self._get_latest_message(message_id_list) if target_message_dict: # 直接使用字典作为action_message,避免DatabaseMessages对象创建失败 @@ -466,7 +474,7 @@ class ChatterPlanFilter: if ( action not in ["no_action", "no_reply", "reply", "do_nothing", "proactive_reply"] - and action not in self.available_actions + and action not in plan.available_actions ): reasoning = f"LLM 返回了当前不可用的动作 '{action}'。原始理由: {reasoning}" action = "no_action" @@ -589,3 +597,15 @@ class ChatterPlanFilter: if not message_id_list: return None return message_id_list[-1].get("message") + + def _find_poke_notice(self, message_id_list: list) -> Optional[Dict[str, Any]]: + """在消息列表中寻找戳一戳的通知消息""" + for item in reversed(message_id_list): + message = item.get("message") + if ( + isinstance(message, dict) + and message.get("type") == "notice" + and "戳" in message.get("processed_plain_text", "") + ): + return message + return None