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

    Now let me look at how the tools are passed from LibreChat's web_search to the agent call, to understand the full picture:

  4. MiniMax Assistant

    Let me look at how tools are loaded for the agent and how Anthropic gets them:

  5. MiniMax Assistant

    Let me look at how the Anthropic LLM receives tools and where the issue is. Look at where the tools (from LibreChat) and the Anthropic-native tools both end up at the LLM:

  6. MiniMax Assistant

    Now let me look at how LibreChat's web_search tool gets loaded into the agent. Let me check the ToolService.js:

  7. MiniMax Assistant

    Now let me look at how Anthropic gets the tools. Looking at loadToolDefinitions for what the Anthropic endpoint receives:

  8. MiniMax Assistant

    Now let me understand the issue better. The web_search tool name appears in two places:

    1. As a LibreChat native tool (Tools.web_search = 'web_search')
    2. As an Anthropic-native tool defined in llm.ts ({ type: 'web_search_20250305', name: 'web_search' })

    If both are enabled, two web_search tools get sent to Anthropic, which rejects them.

    Let me look at how the LibreChat web_search tool gets added to the tool definitions sent to the LLM:

  9. MiniMax Assistant

    Now I understand the flow. Let me look at where the toolDefinitions get sent to the LLM. Looking at options.tools for Anthropic:

  10. MiniMax Assistant

    Now I need to understand how tools end up in options.tools (which is from result returned by initializeAnthropic, where result.tools contains the Anthropic-native web_search tool):

  11. MiniMax Assistant

    So options.tools from initializeAnthropic comes from result.tools which is the Anthropic-native tools array. Let me trace the issue.

    Looking at initialize.ts again:

    let tools: GenericTool[] = options.tools?.length
      ? (options.tools as GenericTool[])
      : (structuredTools ?? []);
    
    if (
      (agent.provider === Providers.OPENAI ||
        agent.provider === Providers.AZURE ||
        agent.provider === Providers.ANTHROPIC) &&
      options.tools?.length &&
      structuredTools?.length
    ) {
      tools = structuredTools.concat(options.tools as GenericTool[]);
    }
    

    So when the provider is Anthropic, both structuredTools (LibreChat tools like web_search) AND options.tools (Anthropic-native tools) get concatenated. This is where the duplicate web_search is created!

    Now let me check how the tools are finally sent to the LLM:

  12. MiniMax Assistant

    Let me look for how the LLM gets bound tools:

  13. MiniMax Assistant

    Now I understand the issue. Let me trace the flow more carefully:

    1. initializeAnthropic returns result which has tools array containing [{ type: 'web_search_20250305', name: 'web_search' }] (Anthropic-native)
    2. loadToolsResult has tools: structuredTools containing LibreChat native tools (could include web_search)
    3. In initialize.ts:
      let tools: GenericTool[] = options.tools?.length
        ? (options.tools as GenericTool[])
        : (structuredTools ?? []);
      
      if (
        (agent.provider === Providers.ANTHROPIC) &&
        options.tools?.length &&
        structuredTools?.length
      ) {
        tools = structuredTools.concat(options.tools as GenericTool[]);
      }
      

    So when both structuredTools contains a web_search tool (LibreChat's) AND options.tools contains the Anthropic-native web_search, we get a duplicate name web_search in the tools array sent to Anthropic.

    Now, the issue says:

    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 need to deduplicate web_search from Anthropic-native tools when the LibreChat web_search is present.

    Let me look at the test file to understand the expected behavior:

  14. MiniMax Assistant

    Now let me look at the broader agent flow to understand the actual merging:

  15. MiniMax Assistant

    Now I see the place where the issue exists. Let me check the agent.initialize test:

  16. MiniMax Assistant

    Now let me search for what other tests exist related to the ANTHROPIC provider path:

  17. MiniMax Assistant

    Let me look at the place where web_search is registered with Tools.web_search:

  18. MiniMax Assistant

    OK, so Tools.web_search = 'web_search'. Now let me also confirm where in the initialize.ts the agent's tools list contains web_search:

  19. MiniMax Assistant

    Now let me trace WebSearchToolDefinition:

  20. MiniMax Assistant

    Confirmed - both have the name web_search. Now let me find where in initialize.ts the fix should happen. The most appropriate place is the concatenation logic that handles Anthropic specifically.

    Now let me think about the proper fix. The issue says:

    When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition.

    So we need to:

    1. Detect when the LibreChat-native web_search tool is in structuredTools AND Anthropic-native web_search tool is in options.tools
    2. When both are present, prefer LibreChat's definition (which is in structuredTools)
    3. The options.tools (Anthropic-native) should be filtered to remove the web_search tool before concatenation

    Let me also consider where else this might happen. Let me check the OPENAI/Azure branch too:

  21. MiniMax Assistant

    OK so the same web_search issue exists for OpenAI as well. But the issue description specifically says "Anthropic", so let me focus on Anthropic first. Let me also look at what other providers might have similar issues:

    Actually, the issue is:

    Do not affect unrelated tools or other providers.

    So the fix should be specific to Anthropic. The deduplication needs to happen only when both LibreChat's web_search and Anthropic-native web_search are present.

    Let me check the existing tests to understand what's expected:

  22. MiniMax Assistant

    Let me look at the tests for initialize:

  23. MiniMax Assistant

    Now let me create a script to reproduce the issue:

  24. MiniMax Assistant

    Now I have enough understanding. Let me write a quick reproduce script. Let me trace what would happen:

    1. The agent has web_search in its tools list
    2. loadToolsResult is called, and through the registry, this becomes structuredTools with [{ name: 'web_search', description: ..., parameters: ... }]
    3. options.tools (from initializeAnthropic) contains [{ type: 'web_search_20250305', name: 'web_search' }]
    4. The concatenation in initialize.ts produces: [{ name: 'web_search', ... }, { type: 'web_search_20250305', name: 'web_search' }]
    5. Anthropic rejects this duplicate.

    The fix needs to be in initialize.ts:

    • When the agent's provider is Anthropic
    • And structuredTools already contains a tool named web_search
    • And options.tools contains a tool with name === 'web_search' (or type === 'web_search_20250305')
    • Then filter out the Anthropic-native one from options.tools before concatenation

    Let me also check the issue more carefully. The structuredTools are GenericTool instances. Let me check what their structure is:

  25. MiniMax Assistant

    Now let me also check the structure of structuredTools more carefully. Looking at loadTools in loadAgentTools (legacy path) it returns objects that have a name property:

  26. MiniMax Assistant

    Let me look at the legacy loadTools to understand how structuredTools gets formed:

  27. MiniMax Assistant

    Let me look at loadTools:

  28. MiniMax Assistant

    Now I need to look at the structuredTools shape:

  29. MiniMax Assistant

    So createSearchTool returns a tool with name: 'web_search'. Now let me look at what the structuredTools array contains:

  30. MiniMax Assistant

    Now let me look at the definitions path (event-driven) to see what tools have what names:

  31. MiniMax Assistant

    Now I need to look at how options.tools gets bound to the LLM. Let me also look at how this is sent to Anthropic API:

  32. MiniMax Assistant

    Let me search for where the actual LLM instance is created from llmConfig:

  33. MiniMax Assistant

    Let me look at the librechat agents package's createAgent (which is used in run.ts):

  34. MiniMax Assistant

    So initializeModel calls model.bindTools(tools). This is where the tools end up bound. So the fix needs to deduplicate before this happens.

    Let me look at where this is called:

  35. MiniMax Assistant

    Now let me look at how the model is created:

  36. MiniMax Assistant

    OK, so toolsForBinding comes from agentContext.getToolsForBinding() which gets the merged tools. Let me look at that:

  37. MiniMax Assistant

    Now let me see graphTools:

  38. MiniMax Assistant

    Now let me look at where graphTools gets populated in our initialize.ts:

  39. MiniMax Assistant

    So tools array gets passed as tools to the initializedAgent, which becomes agentContext.tools in the Graph, and then getToolsForBinding() includes them in the binding to the LLM.

    Now I need to fix the issue. The best place is in the initialize.ts where we determine the final tools array. Let me check the spec for tests:

  40. MiniMax Assistant

    Now I have enough context. Let me think about the fix.

    The cleanest place to fix this is in initialize.ts where the concatenation happens. When both LibreChat's web_search and Anthropic's native web_search are present, we should:

    1. Keep LibreChat's definition (the structuredTools entry)
    2. Remove the Anthropic-native web_search tool from options.tools

    Let me also check what the options.tools structure looks like for Anthropic:

    Looking at llm.ts:

    const tools = [];
    
    if (enableWebSearch) {
      tools.push({
        type: 'web_search_20250305',
        name: 'web_search',
      });
      ...
    }
    

    And what structuredTools looks like - it's a GenericTool[] where each has a .name property.

    Let me now check how tools are filtered in the legacy vs new path:

  41. MiniMax Assistant

    OK. Now let me look at the existing tests for initialize to understand what's being verified:

  42. MiniMax Assistant

    Let me look at the broader pattern of how web_search issue should be handled. Looking at OpenAI as comparison, OpenAI also has the same issue (it has { type: 'web_search' } for native web search):

    Looking at the code:

    } else if (enableWebSearch) {
        /** Standard OpenAI web search uses tools API */
        llmConfig.useResponsesApi = true;
        tools.push({ type: 'web_search' });
    }
    

    But OpenAI's web_search tool type doesn't have a name property — it's just { type: 'web_search' }. So the issue may also exist for OpenAI but the issue is specifically about Anthropic.

    Let me make sure by re-reading the issue:

    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.

    OK so the fix is specifically for Anthropic. The check should look at the tool name web_search specifically.

    Now let me think about the approach. I think the best fix is to:

    1. In initialize.ts, when the provider is Anthropic and we're about to concat options.tools with structuredTools:
      • Check if structuredTools already has a tool named web_search
      • If yes, filter out Anthropic-native web_search tool (which has type: 'web_search_20250305' and name: 'web_search') from options.tools before concatenation

    Let me write a test script first to reproduce:

  43. MiniMax Assistant

    Now let me write a script to reproduce the issue:

  44. MiniMax Assistant

    Good, I've reproduced the issue. Now let me look at the actual fix. I'll modify initialize.ts to add the deduplication logic specifically for Anthropic when both LibreChat's web_search and Anthropic's web_search are present:

  45. MiniMax Assistant

    Now let me look at the existing structure and write the fix:

  46. MiniMax Assistant

    Now I'll implement the fix. The key insight is that we need to:

    1. When the agent is on Anthropic
    2. AND structuredTools already has a tool named web_search
    3. AND options.tools has the Anthropic-native web_search (which has type: 'web_search_20250305')
    4. Filter out the Anthropic-native one before concatenation

    Let me look at the structure carefully. The options.tools array elements have type field (e.g., web_search_20250305). The structuredTools elements have name field.

    Let me write the fix:

  47. MiniMax Assistant

    Now let me make the edit:

  48. MiniMax Assistant

    Now I will implement the fix in initialize.ts:

  49. MiniMax Assistant

    Wait, there's a subtle issue. The original code does tools = structuredTools.concat(options.tools as GenericTool[]) only when options.tools?.length && structuredTools?.length. But my refactored providerTools only filters Anthropic's web_search, and otherwise matches the original behavior. Let me re-check carefully.

    Actually, looking at this more carefully, I think we have a simpler approach: just filter the options.tools before concatenation, only when needed for Anthropic.

    Let me refactor:

  50. MiniMax Assistant

    Hmm, that's getting complicated. Let me think again. The simplest approach is to:

    1. Compute providerTools from options.tools, but for Anthropic when LibreChat web_search is present, filter out the Anthropic-native web_search entry.
    2. Then use the existing logic for concatenation.

    Let me simplify:

  51. MiniMax Assistant

    Wait, I notice there's a subtle bug in my refactor. If providerTools becomes empty after filtering, the existing concatenation won't run because of the providerTools.length > 0 check, and tools remains as options.tools. But we need it to remain as structuredTools.

    Actually, looking more carefully, when the existing logic runs:

    • It uses options.tools?.length (which is unchanged), but providerTools?.length (which may be 0 after filter)
    • If providerTools?.length > 0 is false, then tools stays as options.tools (the value set in the let assignment), which is WRONG.

    I need to be more careful. Let me reconsider:

  52. MiniMax Assistant

    Now let me think again. The existing concatenation logic does:

    • tools = structuredTools.concat(options.tools as GenericTool[])

    For Anthropic with the filter applied, options.tools may have had a web_search removed. But the existing logic uses options.tools?.length (which is the ORIGINAL length, unchanged) as a guard.

    If options.tools.length > 0 originally but providerTools.length === 0 after filtering, we'd concat an empty array with structuredTools, which is fine.

    So my approach is fine. Let me think about the edge case:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }] (only Anthropic native)
    • After filter: providerTools = []
    • The concatenation: structuredTools.concat([]) = structuredTools

    That should work. Let me also check the case when options.tools?.length > 0 is the only condition for going through the concat branch:

    Looking at the code:

    if (
      (agent.provider === Providers.ANTHROPIC) &&
      options.tools?.length &&
      structuredTools?.length
    ) {
      tools = structuredTools.concat(options.tools as GenericTool[]);
    }
    

    OK, so the concat only happens when both arrays are non-empty. This is correct for our case.

    Now let me think about the case where:

    • options.tools = [] (no Anthropic native tools)
    • structuredTools = [{ name: 'web_search', ... }] (LibreChat web_search)

    In this case, options.tools?.length is 0 (falsy), so we don't concat. tools stays as structuredTools from the let assignment. Good.

    What about:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }] (Anthropic native)
    • structuredTools = [{ name: 'web_search', ... }] (LibreChat web_search)
    • After filter: providerTools = []
    • The concat: structuredTools.concat([]) = structuredTools (LibreChat's web_search only)

    What about:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }, { type: 'something_else', ... }]
    • structuredTools = [{ name: 'web_search', ... }] (LibreChat web_search)
    • After filter: providerTools = [{ type: 'something_else', ... }]
    • The concat: structuredTools.concat([{ type: 'something_else', ... }])

    What about edge case where options.tools has multiple web_search_20250305 entries (unlikely but possible):

    • After filter: providerTools = [] (all web_search entries removed)
    • Concat with empty array: structuredTools

    Now let me actually apply the edit. Let me also make sure the existing test still passes - the case where options.tools may be undefined:

  53. MiniMax Assistant

    Let me check the type of options.tools:

  54. MiniMax Assistant

    OK, tools?: unknown[] - so it's optional and typed as unknown[]. My handling of (options.tools ?? []) will work fine.

    Now let me apply the edit:

  55. MiniMax Assistant

    Now let me apply the fix:

  56. MiniMax Assistant

    Now let me think about whether this change affects other providers:

    1. OPENAI: providerTools = optionsToolsList (no filter), so behavior unchanged
    2. AZURE: Same as OpenAI, unchanged
    3. GOOGLE/VERTEXAI: The first if branch checks options.tools?.length (original), still triggers GOOGLE_TOOL_CONFLICT
    4. ANTHROPIC: Filter applies only when LibreChat's web_search is in structuredTools

    Let me think about an edge case where providerTools could end up as [] after filter but options.tools?.length > 0:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }], structuredTools = [{ name: 'web_search', ... }]
    • providerTools = [] (filtered)
    • let tools = providerTools.length > 0 ? providerTools : (structuredTools ?? []); → tools = structuredTools ✓
    • Then the ANTHROPIC branch: options.tools?.length && structuredTools?.length → both truthy, so tools = structuredTools.concat([]) = structuredTools ✓

    Now let me also test the case where options.tools is empty:

    • options.tools = [], structuredTools = [{ name: 'web_search', ... }]
    • providerTools = [] (because optionsToolsList.length > 0 is false, so we use the original which is empty)
    • let tools = structuredTools (since providerTools.length === 0)
    • Then ANTHROPIC branch: options.tools?.length is 0 → falsy, so no concat
    • Result: tools = structuredTools ✓

    Now another case: options.tools = [], structuredTools = []:

    • providerTools = []
    • let tools = (structuredTools ?? []) = []
    • No branches match (all require some non-empty conditions)
    • Result: tools = [] ✓

    Let me also test: options.tools = [{ type: 'web_search_20250305', name: 'web_search' }], structuredTools = []:

    • providerTools = optionsToolsList (the filter check requires structuredTools?.some(...) which is false)
    • let tools = providerTools = [{ type: 'web_search_20250305', name: 'web_search' }]
    • Then ANTHROPIC branch: structuredTools?.length is 0 → falsy, so no concat
    • Result: tools = options.tools (the Anthropic native one) ✓

    And: options.tools = [], structuredTools = [{ name: 'calculator' }]:

    • providerTools = []
    • let tools = structuredTools
    • No branches match
    • Result: tools = structuredTools ✓

    And OpenAI: options.tools = [{ type: 'web_search' }], structuredTools = [{ name: 'web_search' }]:

    • providerTools = optionsToolsList = [{ type: 'web_search' }] (no filter for OpenAI)
    • let tools = providerTools
    • Then OPENAI branch: options.tools?.length && structuredTools?.length → both truthy, so tools = structuredTools.concat(optionsToolsList) = [{ name: 'web_search' }, { type: 'web_search' }]
    • Result: Both LibreChat and OpenAI-native are present (current behavior preserved)

    This is the right behavior - we don't want to change OpenAI behavior since the issue is specific to Anthropic.

    Now let me also confirm my understanding of how structuredTools works for Anthropic. Let me look more carefully at the Tools.web_search check:

  57. MiniMax Assistant

    Good. Let me now look at the existing tests for initialize to understand the test patterns and check if there's a test that should fail before my fix:

  58. MiniMax Assistant

    Now let me run the existing tests for initialize to make sure my fix doesn't break anything:

  59. MiniMax Assistant

    Let me see how to run these tests from the project root:

  60. MiniMax Assistant

    The data-provider package hasn't been built yet. Let me build it:

  61. MiniMax Assistant

    Now I need to install the package locally. Let me also build the api package deps:

  62. MiniMax Assistant

    Good - it's a symlink to packages/data-provider. Now let me run the tests:

  63. MiniMax Assistant

    All 34 tests pass with my fix. Let me also run other related tests:

  64. MiniMax Assistant

    All 742 tests pass with my fix. Now let me also write a small reproduction script to verify the fix works:

  65. MiniMax Assistant

    I see two issues:

    1. Test 2: When Anthropic native web_search is present but no LibreChat web_search, the options.tools should be used (not filtered). But my logic gives calculator only. Let me trace this... Wait, the test 2 has options.tools = [{ type: 'web_search_20250305' }] and structuredTools = [{ name: 'calculator' }]. Since LibreChat doesn't have web_search, the filter doesn't apply. Then providerTools = optionsToolsList = [{ type: 'web_search_20250305' }]. So tools starts with providerTools = [{ type: 'web_search_20250305' }]. Then ANTHROPIC branch checks options.tools?.length && structuredTools?.length - both true, so tools = structuredTools.concat(providerTools) = [{ name: 'calculator' }, { type: 'web_search_20250305' }]. So the test result should be 2, not 1. Let me check my test script logic more carefully... Oh, I see, in my test I used tool.name which doesn't exist for the Anthropic-native one. Let me fix the test:
  66. MiniMax Assistant

    Hmm, my test script has bugs - my fake function computeFinalTools isn't quite the same as the original. Let me trace through. Wait, my test reproduction has a bug - I had providerTools.length > 0 ? providerTools : (structuredTools ?? []) but the original code had:

    let tools: GenericTool[] = options.tools?.length
      ? (options.tools as GenericTool[])
      : (structuredTools ?? []);
    

    So in the original, when options.tools?.length > 0, tools is set to options.tools. In my version, tools is set to providerTools which is the filtered version. So if filter removes everything (providerTools becomes empty), then tools = structuredTools. That changes behavior from the original.

    Let me re-look at the original logic:

    Original:

    let tools: GenericTool[] = options.tools?.length
      ? (options.tools as GenericTool[])
      : (structuredTools ?? []);
    
    if (
      ...
    ) {
      tools = structuredTools.concat(options.tools as GenericTool[]);
    }
    

    In the original:

    • If options.tools has 1 element and structuredTools has 1 element, the final tools are structuredTools.concat(options.tools) = 2 elements
    • If options.tools has 1 element and structuredTools is empty, the final tools are options.tools = 1 element

    In my modified version:

    • If options.tools has 1 element (Anthropic native web_search) and structuredTools has LibreChat web_search:
      • providerTools = [] (filtered)
      • tools = structuredTools (LibreChat web_search)
      • Then ANTHROPIC branch: options.tools?.length && structuredTools?.length → both truthy → tools = structuredTools.concat(providerTools) = structuredTools.concat([]) = structuredTools ✓
    • If options.tools has 1 element (Anthropic native web_search) and structuredTools has calculator:
      • providerTools = optionsToolsList (no filter)
      • tools = providerTools
      • Then ANTHROPIC branch: options.tools?.length && structuredTools?.length → both truthy → tools = structuredTools.concat(providerTools) ✓

    The behavior is correct. My test had an error. Let me re-test:

  67. MiniMax Assistant

    I see several issues in my test logic, but more importantly there's a real issue with the original code AND my fix:

    Let me trace through Case 2 carefully:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }] (length = 1)
    • structuredTools = [{ name: 'calculator', description: 'calc' }] (length = 1)

    In the original code:

    let tools = options.tools?.length ? options.tools : structuredTools;
    // tools = options.tools = [{ type: 'web_search_20250305', name: 'web_search' }]
    

    Then in the ANTHROPIC branch:

    } else if (options.tools?.length && structuredTools?.length) {
      // both truthy, so:
      tools = structuredTools.concat(options.tools);
      // tools = [{name: 'calculator'}, {type: 'web_search_20250305', name: 'web_search'}]
    }
    

    So in the ORIGINAL, the result is 2 tools. But my test got 1. Let me check my fake logic again:

    let tools = providerTools.length > 0 ? providerTools : (structuredTools ?? []);
    

    If providerTools has 1 element (the Anthropic native web_search), then tools = providerTools = [{ type: 'web_search_20250305' }].

    Then the ANTHROPIC branch:

    } else if (options.tools?.length && structuredTools?.length) {
      tools = structuredTools.concat(providerTools);
      // = [{name: 'calculator'}].concat([{type: 'web_search_20250305'}])
      // = [{name: 'calculator'}, {type: 'web_search_20250305'}]
    }
    

    So my test result should be 2 tools. But I got 1. Let me check my test again... oh I see, my test had tools = providerTools.length > 0 ? providerTools : (structuredTools ?? []); then in the Anthropic branch:

    } else if (
      (agent.provider === 'openai' ||
        agent.provider === 'azure' ||
        agent.provider === 'anthropic') &&
      optionsTools?.length &&
      structuredTools?.length
    ) {
      tools = structuredTools.concat(providerTools);
    }
    

    Wait, I need to check optionsTools?.length not providerTools.length. Let me re-read my code...

    Actually my fake function in repro_fix3.js DOES use optionsTools?.length not providerTools.length. So the Anthropic branch should run. But the test result shows only 1 tool. Let me debug:

  68. MiniMax Assistant

    I see the issue! optionsToolsList = (optionsTools ?? []) returns optionsTools as is, which is the full object { tools: [...] } not just the array! My test code was wrong.

    Let me fix the test:

  69. MiniMax Assistant

    Now the test logic is correct. Let me re-run the comprehensive tests:

  70. MiniMax Assistant

    All tests pass. Now let me verify that the actual code in initialize.ts matches my test logic. Let me re-look at the code I changed:

  71. MiniMax Assistant

    Good. Now let me run the actual tests with the TypeScript code to make sure everything is working:

  72. MiniMax Assistant

    All 34 tests still pass. Let me also run more agent tests to make sure nothing else broke:

  73. MiniMax Assistant

    All 1051 tests pass. Now let me also test other related test files:

  74. MiniMax Assistant

    All tests pass. Now let me write a temporary reproduction script that simulates the exact code path:

  75. MiniMax Assistant

    No dist. The Jest test was already sufficient. Let me also check that the change doesn't affect edge cases. Let me re-read the final code:

  76. MiniMax Assistant

    Let me look at the diff to make sure the change is clean:

  77. MiniMax Assistant

    The diff looks clean. Now let me think about edge cases more carefully:

    1. What if options.tools contains an entry that is not strictly { type: 'web_search_20250305', name: 'web_search' } but has type with different casing or whitespace? - We filter by exact type match, so any other tool type is unaffected.

    2. What if structuredTools contains a tool with name: 'web_search' but is NOT actually LibreChat's web_search (e.g., from an MCP server)? - The filter would still apply. But this is consistent with the issue requirement: "When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition." Actually, MCP tools don't typically use the name web_search, so this is unlikely. And the issue specifically says "LibreChat's web search" — if MCP were to expose a tool with the same name, dropping the Anthropic-native is still safe.

    3. What about the structuredTools content for Anthropic? - Looking at the code, structuredTools comes from loadToolsResult.tools which is the full tool instance. Its .name would be 'web_search' for LibreChat's web_search tool.

    4. What if there are multiple web_search_20250305 entries in options.tools? - The filter removes all of them, which is fine (better safe than sorry).

    Let me also check the original behavior when options.tools is not an array but an empty array:

    The original code uses options.tools?.length. With options.tools = undefined, options.tools?.length is undefined. The let assignment becomes structuredTools. My new code uses (options.tools ?? []) as GenericTool[]. With options.tools = undefined, this is []. optionsToolsList.length > 0 is false, so providerTools = optionsToolsList = []. Then let tools = (structuredTools ?? []). Good, this matches.

    1. What about when options.tools is not undefined but not an array? - The type says unknown[], so we should assume it's always an array. My code uses .filter() which is safe for arrays.

    Let me also check what happens with as GenericTool[] cast on (options.tools ?? []):

    Looking at the original code, it uses (options.tools as GenericTool[]). My code does (options.tools ?? []) as GenericTool[]. The cast might fail at runtime if options.tools is not actually an array. Let me verify by looking at the type:

  78. MiniMax Assistant

    It's unknown[], so it could be any array of unknown values. The cast to GenericTool[] is unsafe in general but it matches the existing code pattern.

    Now let me also write a test that verifies the actual code change. Let me look at the existing test pattern:

  79. MiniMax Assistant

    Now let me run a broader test suite to confirm nothing breaks:

  80. MiniMax Assistant

    Hmm, many test failures. Let me check what's happening:

  81. MiniMax Assistant

    Wait, these tests are running from packages/api directory but the path is packages/api/src/agents/.... Let me check what's happening:

  82. MiniMax Assistant

    Oh, my pwd changed to /LibreChat somehow. Let me cd to packages/api:

  83. MiniMax Assistant

    Some failures. Let me check if they're related to my change:

  84. MiniMax Assistant

    All failures are related to integration tests (Redis, cache, etc.) - those require external services and are not related to my change. Let me verify this by checking the specific test files to confirm none of them are related to my change:

  85. MiniMax Assistant

    All failures are in integration test files (.cache_integration., .stream_integration.) which require external services like Redis. These are unrelated to my fix.

    Let me check that the tests I care about (agents, tools, anthropic, openai) all pass:

  86. MiniMax Assistant

    1129 tests pass, 0 failures. My fix is correct.

    Now let me look at the final code one more time to make sure it's clean:

  87. MiniMax Assistant

    Wait, I just noticed something. Looking at the issue more carefully:

    When LibreChat web search and Anthropic-native web search are both enabled, expose one web_search tool and prefer LibreChat's definition.

    Looking at my fix, the let tools = providerTools.length > 0 ? providerTools : (structuredTools ?? []); change might cause a subtle issue. Let me re-examine.

    The original code:

    let tools: GenericTool[] = options.tools?.length
      ? (options.tools as GenericTool[])
      : (structuredTools ?? []);
    

    This means:

    • If options.tools is non-empty, tools = options.tools
    • Otherwise, tools = structuredTools

    My new code:

    let tools: GenericTool[] = providerTools.length > 0 ? providerTools : (structuredTools ?? []);
    

    If filter applies and removes all entries from options.tools, providerTools.length === 0, so tools = structuredTools. Good. Otherwise (no filter or partial filter), providerTools.length > 0, so tools = providerTools. Good.

    Hmm wait, this is actually different from the original behavior. In the original, if options.tools?.length > 0, then tools = options.tools regardless of structuredTools. In my new code, providerTools could be empty even if options.tools?.length > 0 (when filter applies and removes everything). In that case, tools = structuredTools instead of options.tools.

    This is the correct behavior because:

    • When filter applies, all entries in options.tools were Anthropic-native web_search tools
    • We want to drop them and keep structuredTools

    Let me trace once more for edge cases:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }], structuredTools = [{ name: 'web_search' }]
    • providerTools = [] (filter removes web_search)
    • tools = structuredTools (since providerTools.length === 0)
    • ANTHROPIC branch: options.tools?.length && structuredTools?.length → both truthy → tools = structuredTools.concat([]) = structuredTools ✓

    Now an edge case where structuredTools = []:

    • options.tools = [{ type: 'web_search_20250305', name: 'web_search' }], structuredTools = []
    • The filter check structuredTools?.some(...) is false (since structuredTools is empty)
    • So providerTools = optionsToolsList = [{ type: 'web_search_20250305' }]
    • tools = providerTools = [{ type: 'web_search_20250305' }]
    • ANTHROPIC branch: structuredTools?.length is 0 → falsy → no concat
    • Result: tools = [{ type: 'web_search_20250305' }] (Anthropic native) ✓

    Now another edge case: options.tools = [], structuredTools = []:

    • optionsToolsList = []
    • providerTools = [] (filter check requires optionsToolsList.length > 0)
    • tools = (structuredTools ?? []) = []
    • No branches match
    • Result: tools = [] ✓

    Now: options.tools = undefined, structuredTools = []:

    • optionsToolsList = [] (since options.tools is undefined)
    • providerTools = []
    • tools = []
    • Result: tools = [] ✓

    OK my logic is sound. Let me also test the case where the agent's provider is anthropic and structuredTools is undefined:

    Wait, looking at the code, structuredTools comes from loadToolsResult.tools, which is destructured with a default of []. So it's always an array. Good.

    Now let me think about whether I should also fix the issue in the agent.js (librechat code) or elsewhere. Let me look at how this is wired up:

  88. MiniMax Assistant

    Good - loadTools is the function (passed as a parameter). Looking at how it's wired in api/server/services/ToolService.js:

  89. MiniMax Assistant

    Good. The wiring is correct - loadAgentTools is called from initialize.js which loads LibreChat's tools. My fix is in the right place.

    Now let me also consider: are there other places where this issue might arise?

  90. MiniMax Assistant

    Good, only one place. Now let me also look at summarization to ensure the same issue isn't elsewhere:

  91. MiniMax Assistant

    No relevant issue. Now let me also test the new test for my fix:

  92. MiniMax Assistant

    All scenarios pass. Let me also check one more edge case: when options.tools has multiple entries of which some are web_search_20250305:

  93. MiniMax Assistant

    All edge cases pass. The fix handles all the scenarios correctly:

    1. Multiple web_search_20250305 entries: all filtered out, LC kept
    2. Empty structuredTools + Anthropic native: native kept
    3. Mixed tools with LC web_search: only web_search_20250305 filtered, other tools kept
    4. Vertex AI works (uses Anthropic format)
    5. Empty/undefined structuredTools: native kept as is

    Let me also clean up the temporary scripts:

  94. MiniMax Assistant

    Let me look at the final diff:

  95. MiniMax Assistant

    I notice that there are also some package-lock.json and package.json changes. These are not from my changes. They seem to have been changed by npm install. Let me restore them:

  96. MiniMax Assistant

    Only my change remains. Let me re-verify by running the tests once more:

  97. MiniMax Assistant

    All 34 tests still pass.

    Let me also check that the linting passes:

  98. MiniMax Assistant

    ESLint passes. Let me also check TypeScript compilation:

  99. MiniMax Assistant

    TypeScript compiles cleanly. Let me also do a final review of the diff:

  100. MiniMax Assistant

    The diff looks clean and focused. Let me do a final sanity check by re-reading the issue:

    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.

    ✅ When both are enabled: only LibreChat's web_search is in the final tools array (filtered out Anthropic-native web_search_20250305).

    ✅ Unrelated tools: The filter only removes entries with type === 'web_search_20250305', all other tools are preserved.

    ✅ Other providers: The filter is gated on agent.provider === Providers.ANTHROPIC. For OpenAI, Azure, Google, Vertex AI — behavior is unchanged.

    Now let me address the checklist:

    Checklist

    • If an error was reported in the issue description, I have successfully reproduced it.
      • Yes, I reproduced the duplicate web_search issue in /tmp/repro/repro.js and then verified the fix works in subsequent test scripts.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
      • Yes, the fix deduplicates the web_search tool when both LibreChat's native and Anthropic's native are enabled.
    • I have thought about edge cases and made sure my fix handles them as well.
      • Yes, I tested:
        • Both enabled (the main issue)
        • Only Anthropic native
        • Only LibreChat
        • Empty structuredTools
        • Multiple Anthropic native web_search entries
        • Mixed tools (Anthropic native + LibreChat + other tools)
        • Vertex AI
        • OpenAI (unchanged behavior)
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
      • Yes, 1129 tests pass in src/agents/, src/tools/, src/endpoints/anthropic/, src/endpoints/openai/ test directories.

    Let me also check that the issue description states:

    Interface

    No new public interfaces are introduced.

    ✅ My fix is purely internal logic changes - no new public types, classes, or functions are introduced.

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