From db833de69b7f585d60bc09f47cb4c942ee998b00 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Fri, 30 Jan 2026 19:35:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20=E4=BF=AE=E5=A4=8D=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6=E6=97=A0=E6=B3=95=E8=BD=BD=E5=85=A5=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/middlewares/runtime_config_middleware.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/agents/common/middlewares/runtime_config_middleware.py b/src/agents/common/middlewares/runtime_config_middleware.py index 1eaacf0e..731939ad 100644 --- a/src/agents/common/middlewares/runtime_config_middleware.py +++ b/src/agents/common/middlewares/runtime_config_middleware.py @@ -85,9 +85,14 @@ class RuntimeConfigMiddleware(AgentMiddleware): existing_tools = list(request.tools or []) merged_tools = [] for t_bind in existing_tools: - if t_bind in enabled_tools or t_bind not in self.tools: + # (1) 已启用的工具保留 + # (2) 非本中间件管理的工具保留 + if t_bind.name in [t.name for t in enabled_tools] or \ + t_bind.name not in [t.name for t in self.tools]: merged_tools.append(t_bind) overrides["tools"] = merged_tools + logger.debug(f"RuntimeConfigMiddleware selected tools: {[t.name for t in merged_tools]}") + # 3. 系统提示词覆盖(可选) if self.enable_system_prompt_override: @@ -115,8 +120,6 @@ class RuntimeConfigMiddleware(AgentMiddleware): for tool_name in tools: if tool_name in tools_map: selected_tools.append(tools_map[tool_name]) - else: - logger.warning(f"Tool '{tool_name}' not found in available tools. {tools_map.keys()=}") # 2. 知识库工具 knowledges = getattr(context, self.knowledges_context_name, None)