Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Anthropic rejects duplicate websearch tool names When LibreChat web…

  1. User

    ISSUE DESCRIPTION

    Anthropic rejects duplicate web_search tool names

    When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition. Do not affect unrelated tools or other providers.

    Interface

    No new public interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /LibreChat, current file: none) bash-$

  2. MiniMax Assistant

    I'll start by exploring the repository structure to understand the codebase.

  3. MiniMax Assistant

    Let me search for Anthropic-related web search handling:

  4. MiniMax Assistant

    Let me look for where Anthropic tools are defined/added:

  5. MiniMax Assistant

    Now let me find where the web_search tool is added to a request for Anthropic:

  6. MiniMax Assistant

    Found it! Let me look at the relevant section in the anthropic LLM:

  7. MiniMax Assistant

    Now let me look at the relevant tests to understand the existing functionality:

  8. MiniMax Assistant

    Now let me look at where tools is consumed and how the Anthropic request is constructed:

  9. MiniMax Assistant

    Now let's find where these tools are merged with other tools (like the LibreChat ones) before being sent to the Anthropic API:

  10. MiniMax Assistant

    Now I see the architecture. The Anthropic tools (with name: 'web_search') come from getAnthropicLLMConfig, and there are also tools from LibreChat itself. Let me find where these are merged:

  11. MiniMax Assistant

    Let me look at where the tools get sent to the LLM and find the actual merge logic:

  12. MiniMax Assistant

    Now let's look at how the LibreChat web_search tool gets transformed for Anthropic:

  13. MiniMax Assistant

    Now let me find where the actual tools from LibreChat (and the LLM provider) are merged:

  14. MiniMax Assistant

    Let me search for where anthropic tools are bound:

  15. MiniMax Assistant

    Now let me see how the result.tools from getOpenAIConfig is merged with the LibreChat native web_search tools. Let me look at where the actual chat completion request happens:

  16. MiniMax Assistant

    Now I understand! In the initialize.ts file, when agent.provider is ANTHROPIC and both options.tools (from getOpenAIConfig) and structuredTools are present, they are concatenated. The options.tools would include the Anthropic-native web_search tool, and structuredTools would include the LibreChat web_search tool. This causes the duplicate.

    Let me verify by looking at structuredTools:

  17. MiniMax Assistant

    Now let me trace where the tools are turned into Anthropic format. Let me search for how these tools are sent:

  18. MiniMax Assistant

    Let me look at the broader flow of when the request actually goes to Anthropic:

  19. MiniMax Assistant

    Let me look at the createPayload or similar flow:

  20. MiniMax Assistant

    Now let me understand where these tools get translated to Anthropic format. Let me check where structuredTools is converted into tool format for the actual LLM call:

  21. MiniMax Assistant

    Let me look at how the OpenAI/Anthropic client processes tools at runtime:

  22. MiniMax Assistant

    Now let me look at the actual issue. The flow is:

    1. The LLM config generates a web_search tool with type: 'web_search_20250305' (Anthropic-native format)
    2. The user enables LibreChat web_search through the UI / agents config
    3. The LibreChat web_search tool is in the agent's tools array
    4. When loadTools runs, the LibreChat web_search tool is loaded into structuredTools (a DynamicStructuredTool)
    5. When initialize.ts runs for Anthropic provider, it concatenates structuredTools.concat(options.tools)
    6. So we'd end up with both the LibreChat web_search tool AND the Anthropic-native web_search tool sent to the Anthropic API

    Now let's look at where this happens to understand the order and trace where the duplicate would arise:

  23. MiniMax Assistant

    Now I see this is the problem. Let me look more carefully:

  24. MiniMax Assistant

    Let me check the structure of options.tools:

  25. MiniMax Assistant

    Now let me trace where tools from options (the options.tools field) gets to. Let me look at how options are constructed:

  26. MiniMax Assistant

    Now let me look at where the tools from getLLMConfig are returned and processed:

  27. MiniMax Assistant

    Let me check the InitializeResultBase type:

  28. MiniMax Assistant

    Now let me check where the duplicate issue actually manifests. Let me look at the formatStructuredToolToAnthropic function more carefully:

  29. MiniMax Assistant

    Now I understand the picture. The tools from getLLMConfig are raw objects with type and name, like {type: 'web_search_20250305', name: 'web_search'}. They will be passed in agent.tools (or options.tools) array. Then loadTools loads LibreChat's web_search tool. The final tools array then has both, which gets sent to the LLM.

    Let me look at bindTools to understand exactly what gets sent to Anthropic API:

  30. MiniMax Assistant

    Now let me look at isBuiltinTool more carefully - it checks if the tool has type starting with web_search_. The Anthropic-native tool will pass this check. The LibreChat web_search tool when loaded as DynamicStructuredTool will get formatted by isLangChainTool to name: 'web_search'. So we'd end up with two tools having name web_search - one from LibreChat and one from Anthropic - causing the duplicate.

    Now let me write a reproduction script to confirm:

  31. MiniMax Assistant

    Now let me look at the request flow more comprehensively. Let me see how this happens at a high level - what happens with agent.tools:

  32. MiniMax Assistant

    Now I have a clear picture. Let me look at the exact flow more carefully:

    1. The agent config has tools: ['web_search']
    2. The loadTools function loads the LibreChat web_search tool (DynamicStructuredTool) into structuredTools
    3. The getLLMConfig returns tools: [{type: 'web_search_20250305', name: 'web_search'}] from Anthropic
    4. In initialize.ts, line 846: tools = structuredTools.concat(options.tools as GenericTool[])
    5. This produces [librechat_websearchTool, anthropic_websearchTool] both with name web_search
    6. When sent to Anthropic, the Anthropic API rejects duplicate tool names

    Let me look at where the agent.tools get bound to langchain. Let me trace it further:

  33. MiniMax Assistant

    Now let me look at where the request actually gets sent to the LLM. Let me trace where tools flow:

  34. MiniMax Assistant

    So BaseClient.js doesn't have any tool handling. Let me look at OpenAIClient or any custom client:

  35. MiniMax Assistant

    Now let me look at where the actual tools are translated for the OpenAI/Anthropic call. Let me look at openai.js:

  36. MiniMax Assistant

    Now let me look at the test file for initialize.ts to understand the expectations:

  37. MiniMax Assistant

    Now I understand. The issue is in initialize.ts line 829-846. Let me write a test to reproduce:

  38. MiniMax Assistant

    Let me search for tests that test the existing behavior of options.tools being concatenated with structuredTools:

  39. MiniMax Assistant

    Now let me look at how the function calls the loadTools to actually load the LibreChat web_search tool:

  40. MiniMax Assistant

    Now let me think about the actual issue more carefully. Let me look at the existing tests for initialize.ts for tools:

  41. MiniMax Assistant

    Now I understand the structure. Let me write a script to reproduce the bug:

  42. MiniMax Assistant

    Now let me also explore how the actual flow to Anthropic happens. Let me search for the request creation path:

  43. MiniMax Assistant

    Now let me look at the langchain anthropic SDK to confirm how duplicate tool names cause errors:

  44. MiniMax Assistant

    The langchain SDK doesn't have explicit duplicate validation, but the Anthropic API will reject it. Let me look at how the actual Anthropic request is made:

  45. MiniMax Assistant

    Now let me trace exactly what gets sent. Let me look at the structure of the final tools array in initialize.ts:

  46. MiniMax Assistant

    Now let me look at how the request flow uses the result of initializeAgent. I need to confirm this gets bound to langchain and sent. Let me search for where the LLM is created and tools are bound:

  47. MiniMax Assistant

    Now I confirm that formatStructuredToolToAnthropic is called on options?.tools, which is the final tools array from initialize.ts. If it contains both the LibreChat web_search tool AND the Anthropic-native web_search tool, both will get formatted to name: 'web_search' which the Anthropic API will reject.

    Let me write a reproduction script:

  48. MiniMax Assistant

    I've successfully reproduced the issue. Now I need to find the right place to fix this.

    Looking at the issue description again:

    When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition. Do not affect unrelated tools or other providers.

    The fix should:

    1. Expose only ONE web_search tool
    2. Prefer LibreChat's definition
    3. Not affect other tools or providers

    The cleanest place to fix this is in initialize.ts where the concatenation happens. Or we could do it in the Anthropic llm.ts where it generates the tool list. Let me think about both options:

    Option 1: Fix in initialize.ts: When the agent provider is Anthropic, filter out the Anthropic-native web_search tool from options.tools if the LibreChat structuredTools contains a web_search tool.

    Option 2: Fix in anthropic/llm.ts: Don't add the web_search tool to tools if web_search is in the model parameters. But this won't help because we can't tell whether LibreChat's web_search is loaded.

    Option 3: Fix in initialize.ts: Use a single tool — the LibreChat one when available — for both options.tools (LLM-level) and structuredTools.

    The best approach is Option 1. When the agent uses Anthropic and both LibreChat web_search and Anthropic-native web_search are enabled, we should:

    1. Skip the Anthropic-native web_search tool from options.tools
    2. Keep LibreChat's web_search tool

    Let me look at the current structure to implement the fix:

  49. MiniMax Assistant

    Now let me look at the existing imports in initialize.ts:

  50. MiniMax Assistant

    Good. Now let me check the imports for Tools.web_search:

  51. MiniMax Assistant

    Let me check what Tools.web_search evaluates to:

  52. MiniMax Assistant

    So Tools.web_search === 'web_search'. Now let me look at the Tools.web_search import and what name does it have for the LibreChat tool:

  53. MiniMax Assistant

    Good, WebSearchToolName === 'web_search'. Now I need to determine where to make the fix. Let me think about the design carefully.

    The issue is that the tools in options.tools (returned from getLLMConfig) and the LibreChat-native tools in structuredTools both end up with the name 'web_search', and when concatenated, they become duplicates.

    The fix should:

    1. When the agent provider is Anthropic AND LibreChat's web_search tool is loaded, exclude the Anthropic-native web_search tool from options.tools.
    2. Or alternatively, when concatenating tools for Anthropic provider, deduplicate by tool name.

    The simplest and cleanest approach is option 1: filter out the Anthropic-native web_search tool from options.tools when the LibreChat web_search tool is present in structuredTools.

    Let me look more carefully at the structure to ensure the right approach:

  54. MiniMax Assistant

    Now let me also confirm my understanding of isBuiltinTool. The web_search_20250305 tool has type and name fields, so it should be detected as a builtin tool.

    Let me also look at isLangChainTool to confirm a DynamicStructuredTool from LangChain would match it:

  55. MiniMax Assistant

    Now I have a clear understanding. Let me look at how the tools from the dynamicStructuredTool look - they would be StructuredTool instances with lc_namespace. The Anthropic-native web_search tool is a plain object with type and name.

    Now let me design the fix. The cleanest approach is in initialize.ts:

    1. When the agent provider is Anthropic, check if structuredTools already has a tool named web_search (LibreChat's)
    2. If so, filter out the Anthropic-native web_search tool from options.tools

    But there's a more general approach that handles multiple tool conflicts. Let me look at how Google handles this:

  56. MiniMax Assistant

    Now let me look at the OpenAI LLM and see if it adds web_search:

  57. MiniMax Assistant

    So for OpenAI, when enableWebSearch is true, it uses useResponsesApi = true and tools.push({ type: 'web_search' }). This goes through the OpenAI Responses API which handles it differently. Let me check how this is processed through initialize.ts:

  58. MiniMax Assistant

    Now I have a complete picture. Let me design the fix.

    The cleanest approach is to handle this in the initialize.ts file at the point where tools = structuredTools.concat(options.tools as GenericTool[]);. We should filter out any built-in web_search tool from options.tools if the LibreChat web_search tool is in structuredTools. This handles the duplicate tool name issue.

    However, a more general solution would be to deduplicate by tool name. But the issue specifically calls out only the web_search tool, and we should not affect unrelated tools. Let me focus on a precise fix.

    Let me check the issue description again:

    When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition. Do not affect unrelated tools or other providers.

    So we should:

    1. Detect when both LibreChat's web_search and Anthropic-native web_search are present
    2. Expose only one web_search tool
    3. Prefer LibreChat's definition (i.e., keep LibreChat's and remove the native one)

    Let me think about the fix location:

    • Option A: Fix in anthropic/llm.ts - Don't add the Anthropic-native web_search if LibreChat's is going to be loaded
      • But this doesn't know about LibreChat's tools
    • Option B: Fix in initialize.ts - When concatenating tools, filter out the duplicate
      • This has the knowledge of both sides

    Let me go with Option B since it has the right knowledge. Let me look at the structure of options.tools:

  59. MiniMax Assistant

    Now let me implement the fix. Let me look at the existing tests in initialize.test.ts first to ensure I understand the test patterns:

  60. MiniMax Assistant

    Now let me look at the entire initialize.test.ts to understand the test for the Anthropic provider path:

  61. MiniMax Assistant

    No existing tests for Anthropic provider path. Let me look at the overall structure of the test:

  62. MiniMax Assistant

    Now let me look at how the provider-specific tools get into the tools array and what we need to do:

  63. MiniMax Assistant

    Now let me implement the fix. The best place to fix this is in initialize.ts line ~846 where we concatenate the tools. We need to filter out any tools from options.tools that have the same name as a tool in structuredTools, but specifically only for the Anthropic provider and only for the web_search tool.

    Actually, thinking about this more carefully, the most surgical fix would be to just handle the Anthropic web_search case explicitly, since that's the only known conflict (Anthropic is the only provider that uses name instead of type for the web_search built-in).

    Let me implement the fix:

  64. MiniMax Assistant

    Now let me write the fix. I'll modify the concatenation to filter out provider-native web_search tool when LibreChat's web_search is in structuredTools:

  65. MiniMax Assistant

    Now let me implement the fix:

  66. MiniMax Assistant

    Let me try the replace tool instead:

  67. MiniMax Assistant

    Now let me apply this change using sed to modify the file:

  68. MiniMax Assistant

    Let me use a different approach with node:

  69. MiniMax Assistant

    Now let me check if there are any TypeScript errors by looking at the file structure:

  70. MiniMax Assistant

    Let me try to run TypeScript type check:

  71. MiniMax Assistant

    These are general TypeScript errors related to missing modules. Let me focus on the specific file:

  72. MiniMax Assistant

    There's a TypeScript error at line 870: Conversion of type 'GenericTool' to type 'Record<string, unknown>' may be a mistake. Let me look at that:

  73. MiniMax Assistant

    Let me fix the type conversion by using unknown first:

  74. MiniMax Assistant

    My fix is clean (no new errors in initialize.ts). Now let me verify the fix works as expected with a quick test:

  75. MiniMax Assistant

    Right, this is a TS script, let me fix it:

  76. MiniMax Assistant

    The fix works. Now let me also test edge cases:

  77. MiniMax Assistant

    Edge case 7 shows that my test simulates undefined, but in the actual code, structuredTools?.length is already being checked in the if-conditions above. So when we reach the else if block, we know both options.tools?.length and structuredTools?.length are truthy. Let me verify:

  78. MiniMax Assistant

    Good - structuredTools?.length is in the condition, so structuredTools is non-empty array when we reach the code. But structuredTools?.length checks length, not truthy - what if structuredTools = [false]? Well, since it's typed as GenericTool[], that wouldn't happen.

    But to be safer, let me also check tool?.name properly handles potential undefined:

    Actually tool?.name === Tools.web_search is fine because ?.name returns undefined if tool is null/undefined.

    Now let me also test if the changes properly handle the case where the LibreChat web_search tool might not have a name property. Let me look at how the LibreChat tools are structured:

  79. MiniMax Assistant

    The LibreChat web_search tool is a DynamicStructuredTool with name: 'web_search', so my check tool?.name === Tools.web_search works correctly.

    Now let me check the actual libweb_search flow with createSearchTool to ensure the name is indeed 'web_search':

  80. MiniMax Assistant

    Confirmed. The LibreChat web_search tool has name: 'web_search'.

    Now let me look at the loaded tools to see what format they come in. The loadTools returns tools which is the GenericTool[]:

  81. MiniMax Assistant

    Good. So when Tools.web_search is in the tool list, createSearchTool is called which creates a tool with name: 'web_search' (as we confirmed above). This is the LibreChat web_search tool.

    Now let me run the existing tests to make sure I haven't broken anything:

  82. MiniMax Assistant

    There's an issue with running the test directly. Let me try running it from the api directory:

  83. MiniMax Assistant

    The data-provider isn't built. Let me check:

  84. MiniMax Assistant

    The data-provider needs to be built first. Let me check if there's a way to run tests without building:

  85. MiniMax Assistant

    It's a symlink. The package isn't built. Let me check the test setup:

  86. MiniMax Assistant

    Let me check if there are workspace-level setup:

  87. MiniMax Assistant

    Let me check if I can build the data-provider:

  88. MiniMax Assistant

    Data-provider is now built. Now let me also check the data-schemas package:

  89. MiniMax Assistant

    Now let me try the test again:

  90. MiniMax Assistant

    All 34 tests pass. Now let me also run other related tests:

  91. MiniMax Assistant

    All 90 tests pass. Let me also run the endpoints/openai tests:

  92. MiniMax Assistant

    All 218 tests pass. Let me also run the agents tests to be sure:

  93. MiniMax Assistant

    The only failures are in transactions.spec.ts and they're related to MongoBinary download (not related to my changes - it's a pre-existing test infrastructure issue). 718 tests pass.

    Let me check if these failures are pre-existing:

  94. MiniMax Assistant

    So the transactions.spec.ts file actually passes when run in isolation. The previous failures were likely due to test parallelization and the MongoBinary download issue. Not related to my fix.

    Let me also check that I didn't break anything in the API tests:

  95. MiniMax Assistant

    The api package needs to be built:

  96. MiniMax Assistant

    All ToolService tests pass. Now let me write a comprehensive test that proves the fix works:

  97. MiniMax Assistant

    All edge cases are handled correctly. Let me clean up the temporary scripts:

  98. MiniMax Assistant

    Now let me verify the diff for the changes I made:

  99. MiniMax Assistant

    Hmm, package.json and package-lock.json got modified. This is because running tests/builds may have triggered some changes. Let me check what changes happened in package.json:

  100. MiniMax Assistant

    This change was auto-added by npm install. Let me revert it since it's not related to my fix:

  101. MiniMax Assistant

    Now my changes are only in packages/api/src/agents/initialize.ts. Let me view the final diff:

  102. MiniMax Assistant

    The diff is clean. Let me also run the tests one more time to make sure everything is in order:

  103. MiniMax Assistant

    All 34 tests pass. Let me also run the endpoint tests one more time to confirm:

  104. MiniMax Assistant

    All 309 endpoint tests pass.

    Let me also look at the final code to confirm my fix:

  105. MiniMax Assistant

    The fix is complete. Let me also clean up the dist directories I created (so they don't show up as artifacts):

  106. MiniMax Assistant

    The dist directories are gitignored, so they don't show up in git status. My final changes are clean.

    Let me review my checklist:

    Checklist:

    1. If an error was reported in the issue description, I have successfully reproduced it.

      • YES. I created a reproduction script that confirmed the duplicate web_search tool names issue when both LibreChat's web_search tool and Anthropic-native web_search tool are loaded.
    2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.

      • YES. I created multiple verification scripts that confirmed:
        • With the fix, only the LibreChat web_search tool is exposed (not duplicates)
        • The Anthropic-native web_search is kept when no LibreChat web_search is loaded
        • Multiple LibreChat tools are preserved with the Anthropic-native web_search filtered out
        • Other providers (OpenAI, Azure) are not affected
        • Other Anthropic tools are not affected (only the one with name === 'web_search')
    3. I have thought about edge cases and made sure my fix handles them as well.

      • YES. I tested the following edge cases:
        • Only LibreChat web_search (no Anthropic tool) - works
        • Only Anthropic-native web_search (no LibreChat tool) - works
        • Both LibreChat and Anthropic-native web_search - removes only the Anthropic one
        • Neither web_search, only other tools - works
        • OpenAI provider with both web_search tools - not affected (fix is Anthropic-specific)
        • Anthropic with multiple LibreChat tools + web_search conflict - keeps LibreChat tools, removes only Anthropic web_search
        • Anthropic with LibreChat web_search and other Anthropic tools - keeps other Anthropic tools, removes only web_search
    4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.

      • YES. I ran:
        • packages/api/src/agents/__tests__/initialize.test.ts: 34/34 passed
        • packages/api/src/endpoints/anthropic/llm.spec.ts: 90/90 passed
        • packages/api/src/endpoints/openai/*: 218/218 passed
        • api/server/services/__tests__/ToolService.spec.js: 45/45 passed

    My fix is minimal and surgical:

    • Only modifies packages/api/src/agents/initialize.ts in the area where tool concatenation happens
    • Adds a precise filter that only affects the Anthropic provider when LibreChat's web_search tool is present
    • Prefers the LibreChat definition as requested
    • Doesn't affect unrelated tools (other tools in options.tools are preserved)
    • Doesn't affect other providers (the filter only applies when agent.provider === Providers.ANTHROPIC)
    • Includes detailed comments explaining the rationale

    Let me also check if there are any places I might have missed:

  107. MiniMax Assistant

    Only one place does the concatenation, which is what I fixed.

    Let me also check agent.tool_definitions to see if there's another path that handles this:

  108. MiniMax Assistant

    Let me check where tools is used in the agent's tools property (not the parameter) - this might be a different code path:

  109. MiniMax Assistant

    The fix I applied is in the right place. Let me verify the final state:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.