ISSUE DESCRIPTION Anthropic rejects duplicate websearch tool names When LibreChat web…
- 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_searchtool 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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
Assistant
Let me use proper syntax with line numbers not in list form.
Assistant
python3 not available, use node instead.
Assistant
Good, formatting is correct. Now let's check for TypeScript compile errors and run related tests.
Assistant
No errors reported for initialize.ts now. Let's check full output count for remaining errors to ensure none are new/related.
Assistant
All good, no compile errors. Now let's run relevant test suites.
Assistant
All existing tests pass. Now let's write a temporary test script to reproduce the scenario and verify the fix.
Assistant
Now let's write a temporary test script to verify the dedup logic works.
Assistant
The test passes with the fix. Let's verify the fix actually matters by temporarily reverting and confirming test failure.
Assistant
Confirmed the bug reproduces without the fix, and the fix resolves it. Restore the fix.
Assistant
These changes are unrelated environment artifacts from earlier npm operations, not from my edits. Let's revert them to keep the diff clean.
Assistant
Now remove the temporary test file since we shouldn't add new tests to the repo, and clean up dist build artifacts if any were created.
Assistant
Good, those are gitignored so they don't affect the diff. Now let's run the full test suite for the agents initialize module and any anthropic-related tests to be thorough.
Assistant
All 742 tests pass (4 skipped intentionally). Let's also run anthropic endpoint tests and full api package test suite for safety.
Assistant
All pass. Let's run the entire api package test suite once more for final confirmation.
Assistant
Confirmed: these failures are pre-existing due to missing Redis server, unrelated to our change. Our fix is verified. Let's do a final review of the diff.
Assistant
This is a clean, minimal, targeted fix. Now let's review the checklist.
Assistant
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes. I traced the code path:
getLLMConfiginpackages/api/src/endpoints/anthropic/llm.tspushes a native{ type: 'web_search_20250305', name: 'web_search' }tool ontooptions.toolswhen Anthropic-native web search (enableWebSearch) is on. Separately, LibreChat's own web-search plugin (from@librechat/agents'screateSearchTool, viahandleTools.js) also produces a structured tool namedweb_search. Inpackages/api/src/agents/initialize.ts, these were being concatenated unconditionally for theANTHROPIC(andOPENAI/AZURE) providers, producing two tools both namedweb_searchin the final tool list sent to the model — which Anthropic's API rejects. I wrote a temporary Jest test simulating this exact scenario (Anthropic provider, LibreChat web_search structured tool + Anthropic-native web_search tool both present) and confirmed, by stashing my fix, that the test failed withwebSearchCount === 2before the fix — reproducing the reported bug. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. After applying the fix, the same temporary test passed with exactly one
web_searchtool in the result, and it was the LibreChat-authored tool object (verified viatoContain(librechatWebSearchTool)), confirming LibreChat's definition is preferred as required by the issue. The temporary test file was removed afterward per instructions not to add tests to the repo. -
I have thought about edge cases and made sure my fix handles them as well. Yes:
- The dedup only removes provider-native tools whose
namecollides with an existing structured tool'sname; unrelated tools (different names) are untouched. - Tools without a
nameproperty (e.g., OpenAI's native{ type: 'web_search' }object — which lacks anamefield) are unaffected since the filter only compares byname, and Google/Vertex are excluded entirely from this branch (handled by the separateGOOGLE_TOOL_CONFLICTbranch above, untouched by my change). - If
structuredToolsdoesn't contain aweb_search-named tool (i.e., only Anthropic-native search is enabled, not LibreChat's), the provider-native tool is preserved as before — no regression for that case. - The fix is generic (name-based dedup) rather than hardcoded to the literal string
'web_search', so it generalizes to any future provider-native/plugin-name collision without special-casing.
- The dedup only removes provider-native tools whose
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Yes. Ran
src/agents/__tests__/initialize.test.ts(34/34 pass), the entiresrc/agentstest directory (742 passed, 4 intentionally skipped), andsrc/endpoints/anthropictests (91/91 pass). Also ran the fullpackages/apitest suite; the only failures were pre-existing Redis/cache integration tests requiring a live Redis server (confirmed these fail identically with the fix reverted, i.e., unrelated to this change). Also confirmedtsc --noEmitshows no new type errors introduced by the change.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →