From 34bce03f17325b321df94b4eee846b12b9d72dda Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:45:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(proactive):=20=E4=BC=98=E5=8C=96=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E8=81=8A=E5=A4=A9=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=90=9C=E7=B4=A2=E5=89=8D=E5=88=A4=E6=96=AD=E4=B8=8E?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=89=8D=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了提升主动聊天的智能化和自然度,本次更新引入了两个核心优化: 1. **搜索前决策**: 在为主动话题进行网络搜索前,新增一个LLM决策步骤,判断该话题是否有搜索的必要性。这避免了对日常寒暄或无需外部信息的话题进行不必要的搜索,提高了效率。 2. **回复前检查强化**: 严格化了主动回复的触发条件。现在,系统会检查自己的上一条消息是否得到回应,如果无人回应则倾向于保持沉默,以避免连续发言造成打扰。同时,所有判断标准需全部满足才能触发回复,使行为更符合社交直觉。 --- .../chat_loop/proactive/proactive_thinker.py | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/src/chat/chat_loop/proactive/proactive_thinker.py b/src/chat/chat_loop/proactive/proactive_thinker.py index 4abaccebd..d1716e75e 100644 --- a/src/chat/chat_loop/proactive/proactive_thinker.py +++ b/src/chat/chat_loop/proactive/proactive_thinker.py @@ -159,27 +159,46 @@ class ProactiveThinker: news_block = "暂时没有获取到最新资讯。" if trigger_event.source != "reminder_system": - try: - web_search_tool = tool_api.get_tool_instance("web_search") - if web_search_tool: - try: - search_result_dict = await web_search_tool.execute(function_args={"keyword": topic, "max_results": 10}) - except TypeError: + # 增加搜索前决策 + should_search_prompt = f""" +# 搜索决策 + +## 任务 +判断是否有必要为了话题“{topic}”进行网络搜索。 + +## 判断标准 +- **需要搜索**:时事新闻、知识查询、具体事件等需要外部信息的话题。 +- **无需搜索**:日常关心、个人感受、延续已有对话等不需要外部信息的话题。 + +## 你的决策 +输出`SEARCH`或`SKIP`。 +""" + from src.llm_models.utils_model import LLMRequest + from src.config.config import model_config + + decision_llm = LLMRequest( + model_set=model_config.model_task_config.planner, + request_type="planner" + ) + + decision, _ = await decision_llm.generate_response_async(prompt=should_search_prompt) + + if "SEARCH" in decision: + try: + web_search_tool = tool_api.get_tool_instance("web_search") + if web_search_tool and topic: try: search_result_dict = await web_search_tool.execute(function_args={"keyword": topic, "max_results": 10}) - except TypeError: - logger.warning(f"{self.context.log_prefix} 网络搜索工具参数不匹配,跳过搜索") - news_block = "跳过网络搜索。" - search_result_dict = None - - if search_result_dict and not search_result_dict.get("error"): - news_block = search_result_dict.get("content", "未能提取有效资讯。") - elif search_result_dict: - logger.warning(f"{self.context.log_prefix} 网络搜索返回错误: {search_result_dict.get('error')}") - else: - logger.warning(f"{self.context.log_prefix} 未找到 web_search 工具实例。") - except Exception as e: - logger.error(f"{self.context.log_prefix} 主动思考时网络搜索失败: {e}") + if search_result_dict and not search_result_dict.get("error"): + news_block = search_result_dict.get("content", "未能提取有效资讯。") + elif search_result_dict: + logger.warning(f"{self.context.log_prefix} 网络搜索返回错误: {search_result_dict.get('error')}") + except Exception as e: + logger.error(f"{self.context.log_prefix} 网络搜索执行失败: {e}") + else: + logger.warning(f"{self.context.log_prefix} 未找到 web_search 工具实例或主题为空。") + except Exception as e: + logger.error(f"{self.context.log_prefix} 主动思考时网络搜索失败: {e}") message_list = get_raw_msg_before_timestamp_with_chat( chat_id=self.context.stream_id, timestamp=time.time(), @@ -201,15 +220,17 @@ class ProactiveThinker: {chat_context_block} ## 合理判断标准 -请检查以下条件,如果**大部分条件都合理**就可以回复: +请检查以下条件,如果**所有条件都合理**就可以回复: -1. **时间合理性**:当前时间是否在深夜(凌晨2点-6点)这种不适合主动聊天的时段? -2. **内容价值**:这个话题"{topic}"是否有意义,不是完全无关紧要的内容? -3. **重复避免**:你准备说的话题是否与最近2条消息明显重复? -4. **自然性**:在当前上下文中主动提起这个话题是否自然合理? +1. **回应检查**:检查你({bot_name})发送的最后一条消息之后,是否有其他人发言。如果没有,则大概率应该保持沉默。 +2. **话题补充**:只有当你认为准备发起的话题是对上一条无人回应消息的**有价值的补充**时,才可以在上一条消息无人回应的情况下继续发言。 +3. **时间合理性**:当前时间是否在深夜(凌晨2点-6点)这种不适合主动聊天的时段? +4. **内容价值**:这个话题"{topic}"是否有意义,不是完全无关紧要的内容? +5. **重复避免**:你准备说的话题是否与你自己的上一条消息明显重复? +6. **自然性**:在当前上下文中主动提起这个话题是否自然合理? ## 输出要求 -如果判断应该跳过(比如深夜时段、完全无意义话题、明显重复内容),输出:SKIP_PROACTIVE_REPLY +如果判断应该跳过(比如上一条消息无人回应、深夜时段、无意义话题、重复内容),输出:SKIP_PROACTIVE_REPLY 其他情况都应该输出:PROCEED_TO_REPLY 请严格按照上述格式输出,不要添加任何解释。"""