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 start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the repository structure first.
Assistant
Let me search for web_search related code in the codebase.
Assistant
Let me explore the Anthropic-specific code related to web search.
Assistant
Now let me look at the Anthropic-specific LLM endpoint code where web search tools are defined.
Assistant
Let me look at where the Anthropic LLM config tools are used/combined with LibreChat tools.
Assistant
Now let me find where the Anthropic config tools get combined with LibreChat's agent tools.
Assistant
Let me look at the LibreChat web_search tool definition.
Assistant
Let me look at the spec files to understand the expected behavior and existing tests.
Assistant
Let me look at the exact section in initialize.ts where tools get combined.
Assistant
Let me check the Tools enum and how the LibreChat web_search structured tool is named.
Assistant
Let me check the GenericTool type and how tool names are accessed.
Assistant
Let me look at the existing initialize tests for the tool concatenation block.
Assistant
These tests are about the
loadToolscall where agent.tools is passed in. Let me focus on the actual tool concatenation block at line 829-847. The tests here are withProviders.OPENAI(default provider in the helper). Let me check whether there are tests that exercise the concat block withoptions.tools(the provider-specific tools).Let me search for tests that pass
options.tools(result from getOptions) containing the web_search native tool.Assistant
Let me look at the createMocks helper and the loadTools mock structure.
Assistant
Let me look at how
structuredToolsis obtained fromloadTools.Assistant
Let me verify how the LibreChat web_search structured tool is named when loaded.
Assistant
Let me look at the structured tool creation for web_search in handleTools.js to confirm the tool name.
Assistant
Let me look at
createSearchToolto confirm the tool name.Assistant
Let me check createSearchTool in @librechat/agents to confirm the tool name is
web_search.Assistant
Confirmed. Now let me look at the tools.spec.ts test around line 98 to understand how the concat is tested.
Assistant
Now I understand the issue fully. Let me make the fix in
initialize.ts. The fix should deduplicate theweb_searchtool for Anthropic only, preferring LibreChat's definition (instructuredTools).Assistant
Now let me make the edit:
Assistant
Let me check how the native
options.toolsandtoolDefinitionsreach the final API request, to ensure I cover event-driven mode too.Assistant
Let me check the buildToolSet and how toolDefinitions + native tools combine in the agents library.
Assistant
Let me look at how the agents library merges
toolsandtoolDefinitionsfor the actual LLM request.Assistant
Hmm, no results. Let me check how the agents library handles the
toolsfield and native tools. Let me look at the types.Assistant
Let me check whether in event-driven mode
structuredToolsis empty whiletoolDefinitionsholds the LibreChat web_search.Assistant
Let me check how
loadToolsis configured (definitionsOnly mode) in the agents controller.Assistant
I need to handle the event-driven (default) path too, where
structuredToolsis empty buttoolDefinitionsholds LibreChat's web_search. Let me revise the fix to dedupe based on both.Assistant
Let me rewrite the block to handle both legacy and event-driven modes. I'll compute
providerTools(filtered) for Anthropic before the branch logic, based on whether LibreChat's web_search is in structuredTools OR toolDefinitions.Let me replace lines 829-868.
Assistant
Let me verify that the LibreChat web_search is included in
toolDefinitionsin event-driven mode.Assistant
Let me check that
loadToolDefinitionsincludes the web_search definition.Assistant
Let me verify the
LCTooltype has anamefield.Assistant
Now let me run the existing tests to make sure I didn't break anything. First, let me check the test setup.
Assistant
I'm already in packages/api. Let me run from current dir.
Assistant
The module 'librechat-data-provider' isn't resolved. Let me check the jest config and whether the data-provider package is built.
Assistant
I'm in packages/api. Let me use correct paths. Let me check the root jest config and data-provider build status.
Assistant
The root has no jest.config, but the package.json scripts at root mention jest. Wait, the root package.json has
testscript. But there's no jest.config at root? Let me re-check. Earliercat package.json | grep jestshowed jest scripts in... Actually that was the root package.json. But there's no jest.config at root. Let me check the root package.json more carefully — maybe jest config is inline.Actually wait, the earlier
cat packages/api/package.json | grep -A20 '"scripts"'returned the api scripts (test, test:ci, etc.) — but I was IN packages/api so that was actually the root? No... let me re-check. Earlier output showed scripts with "test": "jest --coverage --watch --testPathIgnorePatterns..." which matches the api package.json. Hmm but I rancat packages/api/package.jsonwhile in /LibreChat root at that time. So that WAS the api package.json.So jest config for api is at packages/api. Let me find it.
Assistant
The
librechat-data-provideris a workspace package. Let me check if it's resolvable via node_modules.Assistant
The data-provider has no
distdir, so itsmainentry isn't resolvable. Let me check its package.json main field.Assistant
The data-provider needs to be built. Let me build the dependent packages.
Assistant
Both packages are built now. Let me run the initialize test.
Assistant
All initialize tests pass. Now let me run the Anthropic LLM spec and the tools/agents specs.
Assistant
Both pass. Now let me write a temporary test script to reproduce the duplicate scenario and confirm my fix resolves it for both legacy and event-driven modes.
Assistant
All temporary tests pass. Let me confirm the fix is needed by temporarily reverting and verifying the duplicate would occur without the fix.
Assistant
Confirmed: without the fix, both legacy and event-driven tests fail (duplicate web_search present), and the fix resolves both. Let me check the unexpected package.json/package-lock.json modifications.
Assistant
These package.json/package-lock.json changes are pre-existing environment artifacts (from install), unrelated to my fix. Let me revert them to keep the submission focused on the actual fix.
Assistant
The diff now only contains my fix. Let me re-run the relevant tests to confirm everything still passes after the revert.
Assistant
Now let me remove the temporary test file before submitting.
Assistant
Only
initialize.tsis modified. Let me do a final review of the change.Assistant
The change looks clean and minimal. Let me run the broader agents test suite to ensure nothing else broke.
Assistant
All agents tests pass. Let me run a TypeScript type check on the package to ensure no type errors were introduced.
Assistant
The errors shown are all pre-existing and unrelated to my change (about
EModelEndpoint.custom/agentsindexing in AppConfig, in config/endpoints/resources files — likely from the data-provider build version). Let me confirm my change introduced no type errors specifically ininitialize.ts.Assistant
No type errors in
initialize.ts. The pre-existing errors are in unrelated files (config/endpoints/resources) and exist independent of my change.Let me do a final verification of the complete diff and git status.
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 →
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 →