From e63c5f89942cffb956d0c59ba905b7d7746dccbe Mon Sep 17 00:00:00 2001 From: MumuTW <42820974+MumuTW@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:42:02 +0900 Subject: [PATCH] Fix duplicate predefined tools in dynamic tools system message (#11101) Fix duplicate predefined tools in dynamic system-message section --- core/tools/systemMessageTools/buildToolsSystemMessage.ts | 2 +- .../toolCodeblocks/buildSystemMessage.vitest.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/tools/systemMessageTools/buildToolsSystemMessage.ts b/core/tools/systemMessageTools/buildToolsSystemMessage.ts index 750e6bb43..5948b0445 100644 --- a/core/tools/systemMessageTools/buildToolsSystemMessage.ts +++ b/core/tools/systemMessageTools/buildToolsSystemMessage.ts @@ -40,7 +40,7 @@ export const generateToolsSystemMessage = ( `\nAlso, these additional tool definitions show other tools you can call with the same syntax:`, ); - for (const tool of tools) { + for (const tool of withDynamicMessage) { try { const definition = framework.toolToSystemToolDefinition(tool); instructions.push(`\n${definition}`); diff --git a/core/tools/systemMessageTools/toolCodeblocks/buildSystemMessage.vitest.ts b/core/tools/systemMessageTools/toolCodeblocks/buildSystemMessage.vitest.ts index 669d1c103..4742559ef 100644 --- a/core/tools/systemMessageTools/toolCodeblocks/buildSystemMessage.vitest.ts +++ b/core/tools/systemMessageTools/toolCodeblocks/buildSystemMessage.vitest.ts @@ -191,6 +191,11 @@ describe("generateToolsSystemMessage", () => { const hasDynamicToolsSection = /additional tool definitions/i.test(result); expect(hasDynamicToolsSection).toBe(true); + + // Dynamic definitions should not duplicate tools that already have predefined messages. + expect(result.match(/TOOL_NAME: tool_with_description/g)?.length ?? 0).toBe( + 1, + ); }); it("includes example tool definition and call", () => {