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
I’ll locate the Anthropic tool assembly path and existing web-search definitions/tests, then reproduce the duplicate-name construction before applying a narrowly scoped deduplication.
- Assistant
rgis unavailable, so I’ll use recursivegrepand constrain the search to source/test files to identify where provider-native and LibreChat tools are merged. - Assistant
The provider-native definition is in the Anthropic compatibility configuration. I’ll inspect its tool transformation and call sites, plus the nearby Anthropic tests, to determine whether collision handling belongs in config generation or the later merge with LangChain/LibreChat tools.
- Assistant
I’ll read the Anthropic configuration function and initialization flow to see exactly when runtime tools are available relative to native tool creation.
- Assistant
getLLMConfigcannot know about LibreChat tools, so the correct collision point is likely where initialization’s nativetoolsresult is combined with loaded agent tools. I’ll traceInitializeResultBase.toolsconsumers. - Assistant
The agent initialization layer receives both provider options and resolved tools. I’ll inspect its construction around
getOptions, model creation, and tool binding, including tests that mock native tools. - Assistant
The merge currently concatenates native provider tools after LibreChat tools for OpenAI/Anthropic. I’ll inspect the full provider condition and
GenericToolshape to implement Anthropic-only removal of the native definition when LibreChat already supplies a namedweb_search, preserving order and every unrelated tool. - Assistant
I’ve reproduced the defect directly from the merge logic: for Anthropic, a structured LibreChat tool named
web_searchis concatenated with{type: 'web_search_20250305', name: 'web_search'}unchanged. Before editing, I’ll inspect test fixtures and package scripts so I can exercise this exact branch without altering tests. - Assistant
The narrow fix is to filter only Anthropic’s native built-in (
name: web_searchwith aweb_search_*type) and only when a loaded LibreChat structured tool has that name. This leaves OpenAI/Azure behavior and all other native/regular tools untouched. I’ll add a small internal predicate/helper near the merge and use it only in the Anthropic branch. - Assistant
python3is unavailable, so no edit occurred (confirmed by the empty diff). I’ll perform the same exact replacement with Node, then inspect formatting and the resulting patch. - Assistant
The patch is formatted and scoped as intended. I’ll run the existing agent initializer suite first; it covers provider merge behavior and guards against regressions in unrelated providers/tools.
- Assistant
That test command used a nonexistent config path. I’ll locate the repository’s Jest configuration and rerun from the package context using its established script/config resolution.
- Assistant
I found
packages/api/jest.config.mjs; I’ll rerun the targeted suite with that config. - Assistant
The suite is blocked because the workspace package
librechat-data-providerhas not been built/linked in this checkout, not by the patch. I’ll inspect root workspace scripts and package resolution, then build the minimum dependency needed to execute tests. - Assistant
The workspace symlink exists but its declared
distentry is absent. I’ll buildpackages/data-provider, then rerun the initializer tests. Generated ignored build artifacts will not be submitted. - Assistant
The first dependency now resolves; Jest next reports the same missing-dist condition for
@librechat/data-schemas. I’ll build that workspace package and rerun. - Assistant
The existing initializer suite passes (34/34). To verify TypeScript accepts the
GenericToolaccess and ensure the package compiles end-to-end, I’ll buildpackages/api; this also catches integration/type errors that Jest transpilation may not. - Assistant
The API build succeeds. Running npm with the environment’s newer version modified root package metadata (likely the package-manager field/lockfile) even though no dependencies were intentionally changed. I’ll inspect and revert only those incidental files, preserving the source fix.
- Assistant
Only the intended source file remains modified. I’ll do a final call-site search to ensure there isn’t a second Anthropic/native merge path outside agent initialization that could still produce the duplicate, then review the complete diff.
- Assistant
The search confirms this is the sole merge site. The logic handles edge cases deliberately: no LibreChat web search leaves native search intact; no native search leaves LibreChat intact; unrelated native tools survive filtering; and OpenAI/Azure remain unchanged. I’ll run targeted ESLint and one final diff check before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.