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
Now let's find where
getProviderConfig/getOptionsresult's.toolsis used together with tool definitions (loaded LibreChat tools like web_search) to build final tool list for the LLM/agent run.Assistant
Found the merge point. Let's view around lines 780-860.
Assistant
Now let's implement the dedup logic.
Assistant
The edit applied correctly despite the bash history expansion warning (the
!inside the -e script was history-expanded but harmlessly, the actual replace happened via the string that was already read). Let's verify the file compiles correctly with TypeScript check.Assistant
This tsc failure is a pre-existing environment issue (missing built dist for workspace deps), not related to our change. Let's instead run the relevant jest test suite for initialize.ts directly.
Assistant
Need to build data-provider and data-schemas packages first.
Assistant
All existing tests pass. Now let's write a quick reproduction test to verify the fix behavior directly.
Assistant
Test confirms fix works. Let's verify it fails without the fix (sanity check) by temporarily reverting, then re-apply.
Assistant
Confirmed the issue reproduces without the fix and is resolved with it. Restore the fix.
Assistant
That's from npm install side-effects, unrelated to our fix. Let's revert those unrelated changes.
Assistant
Now remove the temp test file and check dist directories built earlier (data-provider/data-schemas) aren't tracked as changes (they're gitignored presumably).
Assistant
Good, dist dirs are gitignored. Now let's run the full existing test suite for agents/initialize.ts and related web/anthropic tests to make sure nothing broke.
Assistant
All relevant tests pass (191 total). Let's also run the full test suite for packages/api to make sure nothing else broke.
Assistant
All 5144 tests pass (10 skipped, 1 suite skipped - likely pre-existing). Let's check final diff and clean up dist directories we built.
Assistant
The diff is clean and minimal, only touching the relevant merge logic in
initialize.ts. This fix is general (works for any provider-native tool name collision, not justweb_search), only affects OpenAI/Azure/Anthropic branch (leaves Google's separate conflict-detection logic and other providers untouched), and prefers LibreChat's own tool definitions.Assistant
Summary
Root cause: In
packages/api/src/agents/initialize.ts, when combining LibreChat's own loaded tools (structuredTools) with provider-native tools (options.tools, e.g. Anthropic's built-inweb_search_20250305tool), the code for the OpenAI/Azure/Anthropic branch simply didstructuredTools.concat(options.tools). If both LibreChat's plugin tool and Anthropic's native tool were enabled at the same time, the resulting tool list contained two tools both named , which Anthropic's API rejects.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.