From 6400bf87bab731527ca3261486fed5ca284d5df0 Mon Sep 17 00:00:00 2001 From: TeslaZY Date: Wed, 24 Dec 2025 13:26:48 +0800 Subject: [PATCH] Fix: LLM tool does not exist in multiple retrieval case (#12143) ### What problem does this PR solve? Fix LLM tool does not exist in multiple retrieval case ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/component/agent_with_tools.py | 15 +++++++++++---- rag/prompts/generator.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/agent/component/agent_with_tools.py b/agent/component/agent_with_tools.py index f931f2f18..5ff55adf9 100644 --- a/agent/component/agent_with_tools.py +++ b/agent/component/agent_with_tools.py @@ -86,8 +86,9 @@ class Agent(LLM, ToolBase): self.tools = {} for idx, cpn in enumerate(self._param.tools): cpn = self._load_tool_obj(cpn) - name = cpn.get_meta()["function"]["name"] - self.tools[f"{name}_{idx}"] = cpn + original_name = cpn.get_meta()["function"]["name"] + indexed_name = f"{original_name}_{idx}" + self.tools[indexed_name] = cpn self.chat_mdl = LLMBundle(self._canvas.get_tenant_id(), TenantLLMService.llm_id2llm_type(self._param.llm_id), self._param.llm_id, max_retries=self._param.max_retries, @@ -95,7 +96,12 @@ class Agent(LLM, ToolBase): max_rounds=self._param.max_rounds, verbose_tool_use=True ) - self.tool_meta = [v.get_meta() for _,v in self.tools.items()] + self.tool_meta = [] + for indexed_name, tool_obj in self.tools.items(): + original_meta = tool_obj.get_meta() + indexed_meta = deepcopy(original_meta) + indexed_meta["function"]["name"] = indexed_name + self.tool_meta.append(indexed_meta) for mcp in self._param.mcp: _, mcp_server = MCPServerService.get_by_id(mcp["mcp_id"]) @@ -109,7 +115,8 @@ class Agent(LLM, ToolBase): def _load_tool_obj(self, cpn: dict) -> object: from agent.component import component_class - param = component_class(cpn["component_name"] + "Param")() + tool_name = cpn["component_name"] + param = component_class(tool_name + "Param")() param.update(cpn["params"]) try: param.check() diff --git a/rag/prompts/generator.py b/rag/prompts/generator.py index d11cc2ce5..3541fae3b 100644 --- a/rag/prompts/generator.py +++ b/rag/prompts/generator.py @@ -339,7 +339,7 @@ def tool_schema(tools_description: list[dict], complete_task=False): } for idx, tool in enumerate(tools_description): name = tool["function"]["name"] - desc[f"{name}_{idx}"] = tool + desc[name] = tool return "\n\n".join([f"## {i+1}. {fnm}\n{json.dumps(des, ensure_ascii=False, indent=4)}" for i, (fnm, des) in enumerate(desc.items())])