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", () => {