From d45eb419457e3b3f25193a79dd4e780bf183d858 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 15 Sep 2025 12:33:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(proactive):=20=E4=BC=98=E5=8C=96=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E6=80=9D=E8=80=83=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E6=90=9C=E7=B4=A2=E5=86=B3=E7=AD=96=E4=B8=8E=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=9E=8D=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 升级了搜索决策模型,使其能更准确地区分依赖“外部信息”的话题和依赖“内部信息”的社交话题,从而减少不必要的网络搜索。 - **精确决策**: 新的判断原则引导模型更深入地分析话题本质,避免为个人感受或日常闲聊等话题启动搜索。 - **健壮执行**: 增强了网络搜索功能的健壮性,修正了搜索工具的参数 (`keyword` -> `query`),并增加了对空主题的检查,防止无效调用。 - **自然融合**: 优化了最终回复的生成提示,引导模型将获取到的网络信息更自然地融入对话,作为话题的补充或引子,而不是生硬地复述。 --- .../chat_loop/proactive/proactive_thinker.py | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/chat/chat_loop/proactive/proactive_thinker.py b/src/chat/chat_loop/proactive/proactive_thinker.py index d1716e75e..3cbcc2529 100644 --- a/src/chat/chat_loop/proactive/proactive_thinker.py +++ b/src/chat/chat_loop/proactive/proactive_thinker.py @@ -159,19 +159,28 @@ class ProactiveThinker: news_block = "暂时没有获取到最新资讯。" if trigger_event.source != "reminder_system": - # 增加搜索前决策 + # 升级决策模型 should_search_prompt = f""" # 搜索决策 ## 任务 -判断是否有必要为了话题“{topic}”进行网络搜索。 +分析话题“{topic}”,判断它的展开更依赖于“外部信息”还是“内部信息”,并决定是否需要进行网络搜索。 -## 判断标准 -- **需要搜索**:时事新闻、知识查询、具体事件等需要外部信息的话题。 -- **无需搜索**:日常关心、个人感受、延续已有对话等不需要外部信息的话题。 +## 判断原则 +- **需要搜索 (SEARCH)**:当话题的有效讨论**必须**依赖于现实世界的、客观的、可被检索的外部信息时。这包括但不限于: + - 新闻时事、公共事件 + - 专业知识、科学概念 + - 天气、股价等实时数据 + - 对具体实体(如电影、书籍、地点)的客观描述查询 + +- **无需搜索 (SKIP)**:当话题的展开主要依赖于**已有的对话上下文、个人情感、主观体验或社交互动**时。这包括但不限于: + - 延续之前的对话、追问细节 + - 表达关心、问候或个人感受 + - 分享主观看法或经历 + - 纯粹的社交性互动 ## 你的决策 -输出`SEARCH`或`SKIP`。 +根据以上原则,对“{topic}”这个话题进行分析,并严格输出`SEARCH`或`SKIP`。 """ from src.llm_models.utils_model import LLMRequest from src.config.config import model_config @@ -185,18 +194,23 @@ class ProactiveThinker: 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}) - 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}") + if topic and topic.strip(): + 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={"query": topic, "max_results": 10} + ) + 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 工具实例。") else: - logger.warning(f"{self.context.log_prefix} 未找到 web_search 工具实例或主题为空。") + logger.warning(f"{self.context.log_prefix} 主题为空,跳过网络搜索。") except Exception as e: logger.error(f"{self.context.log_prefix} 主动思考时网络搜索失败: {e}") message_list = get_raw_msg_before_timestamp_with_chat( @@ -280,6 +294,8 @@ class ProactiveThinker: - 如果有什么想分享的想法,就自然地开启话题 - 如果只是想闲聊,就随意地说些什么 +**重要**:如果获取到了最新的网络信息(news_block不为空),请**自然地**将这些信息融入你的回复中,作为话题的补充或引子,而不是生硬地复述。 + ## 要求 - 像真正的朋友一样,自然地表达关心或好奇 - 不要过于正式,要口语化和亲切