Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek/deepseek-v4-pro· deepseekHugging 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. DeepSeek Assistant

    Let me start by exploring the repository structure to understand the codebase and find relevant files related to the issue.

    The issue is about:

    1. When LibreChat web search and Anthropic-native web search are both enabled, it exposes one web_search tool and prefers LibreChat's definition.
    2. Don't affect unrelated tools or other providers.

    Let me explore the repository structure first.

  3. DeepSeek Assistant

    Let me search for relevant files related to web_search, anthropic, and tool handling

  4. DeepSeek Assistant

    Let me look at the key files involved. The issue is about duplicate web_search tool names when both LibreChat and Anthropic web search are enabled. Let me check the core

  5. DeepSeek Assistant

    Let me look at the handleTools.js file first

  6. DeepSeek Assistant

    Now let me look at the Anthropic web search tool and how tools are loaded for Anthropic specifically

  7. DeepSeek Assistant

    Let me look at the tools schema and handlers for Anthropic

  8. DeepSeek Assistant

    Let me look at the agent load and the anthropic-specific handling

  9. DeepSeek Assistant

    Let me look at the agents handlers and the tools.spec.ts for anthrop

  10. DeepSeek Assistant

    Let me look at the tools.ts in

  11. DeepSeek Assistant

    Let me look at the agents handlers spec and the handlers.ts for the web_search deduplication

  12. DeepSeek Assistant

    Let me look at the handlers.ts file

  13. DeepSeek Assistant

    Let me look at agents/added.ts which seems relevant

  14. DeepSeek Assistant

    Now let me look at the specific Anthropic llm.ts and where the native web_search is added

  15. DeepSeek Assistant

    Now I understand the flow. Let me see how the Anthropic LLM config tools are merged with loaded tools. Let me look at the llm.spec.ts for Anthropic:

  16. DeepSeek Assistant

    Let me find where getLLMConfig is called to see how its tool results are merged

  17. DeepSeek Assistant

    Let me look at the Anthropic initialize.ts to understand how tools are merged

  18. DeepSeek Assistant

    Let me search for where initializeAnthropic is called to see how tools get

  19. DeepSeek Assistant

    Let me look at providers.ts:

  20. DeepSeek Assistant

    Now let me find where the tools from getLLMConfig are used/m

    <|DSML|tool_calls> <|DSML|invoke name="bash_terminal"> <|DSML|parameter name="command" string="true">cd /LibreChat && grep -rn ".tools\b" --include=".ts" --include=".js" packages/api/src/endpoints/anthropic/ | grep -v node_modules | grep -v ".spec."</|DSML|parameter> </|DSML|invoke> </|DSML|tool_calls>

  21. DeepSeek Assistant

    Let me find where the Anthropic tools are used/

  22. DeepSeek Assistant

    The grep might not match anything. Let me search more broadly.

  23. DeepSeek Assistant

    Let me look at the types to see what InitializeResultBase returns

  24. DeepSeek Assistant

    Let me look at the LLMConfigResult type in openai.ts:

  25. DeepSeek Assistant

    Let me see the full LLMConfigResult type:

  26. DeepSeek Assistant

    Now let me find where the tools from InitializeResultBase are combined with loaded agent tools:

  27. DeepSeek Assistant

    Let me look at the initialize.ts in agents to understand the tool merging:

  28. DeepSeek Assistant

    Let me look at the part of initialize.ts around lines 800-900 where tools are merged:

  29. DeepSeek Assistant

    Let me look at the full initializeAgent function:

  30. DeepSeek Assistant

    Let me look at the function from line 355

  31. DeepSeek Assistant

    Let me search for where getOptions and options.tools come from in initialize.ts:

  32. DeepSeek Assistant

    Let me look at lines 724-750

  33. DeepSeek Assistant

    Now I have a clear understanding of the issue. Let me look at the key area where the fix needs to be applied. The issue is in initialize.ts where structuredTools (LibreChat tools) and options.tools (provider-native tools from getLLMConfig) are concatenated. For Anthropic, when both LibreChat web_search and Anthropic-native web_search are enabled, duplicates occur.

    Let me look more at the structuredTools loading to understand the full

  34. DeepSeek Assistant

    Let me see where structuredTools is defined:

  35. DeepSeek Assistant

    Let me look at line 675-685

  36. DeepSeek Assistant

    Now I have a clear understanding. Let me create a reproduction script and then implement the fix.

    First, let me understand the existing test structure:

  37. DeepSeek Assistant

    Let me look at how tools are tested in initialize tests

  38. DeepSeek Assistant

    Let me look at the test around that line to understand the expected

  39. DeepSeek Assistant

    Now I understand the issue fully. Let me implement the fix. The problem is in packages/api/src/agents/initialize.ts at lines 842-846 where structuredTools (LibreChat-loaded tools) are concatenated with options.tools (provider-native tools from getLLMConfig). When both LibreChat web_search and Anthropic-native web_search are enabled, duplicates occur.

    The fix: filter out provider-native tools that have names already present in LibreChat-loaded tools, so LibreChat's definition is

  40. DeepSeek Assistant

    Let me open the file and look at the area to fix:

  41. DeepSeek Assistant

    Now I can see the exact code to fix. The issue is on line 846 where options.tools (provider-native tools like Anthropic's web_search) are concatenated with structuredTools (LibreChat-loaded tools). When both have web_search, Anthropic rejects the duplicate.

    Let me implement the fix:

  42. DeepSeek Assistant

    Let me try with the replace command instead

  43. DeepSeek Assistant

    The fix looks correct. Now let me verify by running the existing tests related to this area:

  44. DeepSeek Assistant

    Let me fix the jest command

  45. DeepSeek Assistant

    The test has a parse error. Let me check if my edit introduced a TypeScript error by looking at the file again

  46. DeepSeek Assistant

    The TypeScript errors are pre-existing module issues. Let me check the jest error more carefully

  47. DeepSeek Assistant

    The test error is pre-existing in the test file (babel parsing issue, not related to my change). Let me verify my change is syntactically correct

  48. DeepSeek Assistant

    Let me also check the OpenAI llm.ts to see if it also has the web_search tool in its options.tools:

  49. DeepSeek Assistant

    Let me see the OpenAI web_search tool definition:

  50. DeepSeek Assistant

    Let me check the BindToolsInput type to understand the shape:

  51. DeepSeek Assistant

    Let me check whether the OpenAI web_search tool has a name property:

  52. DeepSeek Assistant

    Let me verify the fix is complete by checking if there are other code paths where tools are merged

  53. DeepSeek Assistant

    Let me look at the openai service.ts to check for another tool merging path

  54. DeepSeek Assistant

    Let me also check if Google has a similar web_search tool issue:

  55. DeepSeek Assistant

    Let me also look at the ToolService.js in the API server to see if it has the same issue

  56. DeepSeek Assistant

    Let me look at the loadAgentTools function in ToolService.js to see if it does tool merging with provider tools:

  57. DeepSeek Assistant

    Let me look at the loadAgentTools function:

  58. DeepSeek Assistant

    Let me check the loadToolDefinitionsWrapper function:

  59. DeepSeek Assistant

    Let me look at loadToolDefinitionsWrapper

  60. DeepSeek Assistant

    Let me check if there's a separate code path for non-agent Anthropic chat that might have the same issue:

  61. DeepSeek Assistant

    Let me check the v1.js file to see if there's another tool merging path:

  62. DeepSeek Assistant

    Let me also check the openai config.ts to see how Anthropic's getLLMConfig is used there:

  63. DeepSeek Assistant

    Let me check how it's used:

  64. DeepSeek Assistant

    Let me see the context around line 103:

  65. DeepSeek Assistant

    Let me check where the tools variable goes:

  66. DeepSeek Assistant

    Let me look at the full config.ts to understand the flow better:

  67. DeepSeek Assistant

    Let me check who calls getOpenAIConfig:

  68. DeepSeek Assistant

    Let me verify the fix is correct and run the relevant tests. Let me first check if there are unit tests for the initializeAgent function that test tool merging:

  69. DeepSeek Assistant

    Let me try the full path:

  70. DeepSeek Assistant

    Let me verify this is a pre-existing test failure by reverting my change temporarily and running the test:

  71. DeepSeek Assistant

    Good - the test was already failing before my change. Let me restore my fix:

  72. DeepSeek Assistant

    Let me check if the package.json changes are pre-existing:

  73. DeepSeek Assistant

    Good. Let me verify my change with git

  74. DeepSeek Assistant

    Let me now run the tests for related files that might be affected:

  75. DeepSeek Assistant

    Let me try running some tests that might work:

  76. DeepSeek Assistant

    There seems to be a widespread babel parsing issue. Let me check if there's a babel config:

  77. DeepSeek Assistant

    The babel config seems fine. Let me check the exact line causing the parse error in the test:

  78. DeepSeek Assistant

    Let me see if there's a jest config that sets up babel correctly:

  79. DeepSeek Assistant

    Let me try running with the packages/api jest config

  80. DeepSeek Assistant

    Let me check if there are any tests that specifically test tool deduplication or the Anthropic web_search merge behavior:

  81. DeepSeek Assistant

    Let me search for where Anthropic tools might be assembled in the api/ directory:

  82. DeepSeek Assistant

    Let me look at the nativeTools usage in ToolService.js:

  83. DeepSeek Assistant

    Let me look at how tools from getOpenAIConfig is used in the non-agent Anthropic chat path:

  84. DeepSeek Assistant

    Let me look at the full return of getOpenAIConfig:

  85. DeepSeek Assistant

    Let me check if there's a non-agent Anthropic path that might also duplicate web_search:

  86. DeepSeek Assistant

    Let me check the tools.js controller:

  87. DeepSeek Assistant

    My fix is in the right place. Let me do a final review of the change

  88. DeepSeek Assistant

    Let me create a quick test script to verify the deduplication logic works correctly

  89. DeepSeek Assistant

    Let me write a temp script file instead:

  90. DeepSeek Assistant

    Let me test edge cases too:

  91. DeepSeek Assistant

    Let me clean up temp files and verify TypeScript syntax:

  92. DeepSeek Assistant

    Let me also check if there's a relevant test for the API server ToolService:

  93. DeepSeek Assistant

    Let me verify my change one final

  94. DeepSeek Assistant

    My change is complete. Let me provide a summary:

    Summary

    Issue: When both LibreChat web search and Anthropic-native web search are both enabled, Anthropic rejects duplicate web_search tool names.

    Root Cause: In packages/api/src/agents/initialize.ts, when initializing an agent for Anthropic (and OpenAI/Azure), the code concatenates structuredTools (LibreChat-loaded tools from handleTools.js) with options.tools (provider-native tools from getLLMConfig). When both sources contain a web_search tool, duplicates occur:

    • LibreChat's web_search comes from loadTools → handleTools.js → createSearchTool
    • Anthropic-native web_search comes from getLLMConfig in endpoints/anthropic/llm.ts

    Fix: Before concatenation, filter out provider-native tools whose names already exist in LibreChat-loaded tools. This ensures:

    1. LibreChat's web_search definition is preferred (it comes first in the concatenated array)
    2. Anthropic-native web_search is excluded when it would duplicate
    3. Unrelated tools with different names are unaffected
    4. Other providers are unaffected (the logic applies but there are no current name collisions)

    The fix is in packages/api/src/agents/initialize.ts, modifying the tool concatenation logic to add deduplication by tool name.

    Checklist

    • ✅ Reproduced the error: I traced the code to understand the root cause - duplicate web_search tool names from two sources when both are enabled.

    • ✅ Confirmed the fix resolves the error: Verified the deduplication logic works correctly with test scripts covering edge cases (Anthropic native filtered, OpenAI no-name tools preserved, no collisions preserved).

    • ✅ Considered edge cases:

      • OpenAI tools without name property → not incorrectly filtered
      • Only Anthropic-native web_search enabled → kept
      • Only LibreChat web_search enabled → kept
      • Neither enabled → not affected
      • Other providers (OpenAI, Azure) → logic applies but no current name collisions
    • ✅ Run existing tests: The relevant test files (initialize.test.ts, tools.spec.ts) have pre-existing babel parsing errors unrelated to my change. Confirmed by reverting my change and running tests - they fail identically.

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