fix(agent): 修复中间件无法载入知识库工具

This commit is contained in:
Wenjie Zhang 2026-01-30 19:35:11 +08:00
parent db8b2b4460
commit db833de69b

View File

@ -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)