From 9b7c5be780462984d8d70bf3b32c4d64675b323e Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Sat, 13 Sep 2025 15:14:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(chat):=20=E4=BC=98=E5=8C=96plan=5Ffilt?= =?UTF-8?q?er=E4=B8=AD=E7=9A=84=E5=9B=9E=E5=A4=8D=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 `reply_action_added` 标志位,确保在一次处理中只添加一个回复类型的动作(如 `reply` 或 `proactive_reply`)。 - 优化了循环和条件判断逻辑,使代码更清晰、更健壮,防止因LLM返回多个回复动作而导致的意外行为。 --- src/chat/planner_actions/plan_filter.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/chat/planner_actions/plan_filter.py b/src/chat/planner_actions/plan_filter.py index 32ad9586b..f56bcf60e 100644 --- a/src/chat/planner_actions/plan_filter.py +++ b/src/chat/planner_actions/plan_filter.py @@ -49,6 +49,7 @@ class PlanFilter: llm_content, _ = await self.planner_llm.generate_response_async(prompt=prompt) if llm_content: + logger.debug(f"LLM a原始返回: {llm_content}") parsed_json = orjson.loads(repair_json(llm_content)) if isinstance(parsed_json, dict): @@ -56,13 +57,33 @@ class PlanFilter: if isinstance(parsed_json, list): final_actions = [] + reply_action_added = False + # 定义回复类动作的集合,方便扩展 + reply_action_types = {"reply", "proactive_reply"} + for item in parsed_json: - if isinstance(item, dict): + if not isinstance(item, dict): + continue + + # 预解析 action_type 来进行判断 + action_type = item.get("action", "no_action") + + if action_type in reply_action_types: + if not reply_action_added: + final_actions.extend( + await self._parse_single_action( + item, used_message_id_list, plan + ) + ) + reply_action_added = True + else: + # 非回复类动作直接添加 final_actions.extend( await self._parse_single_action( item, used_message_id_list, plan ) ) + plan.decided_actions = self._filter_no_actions(final_actions) except Exception as e: