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 understanding the issue:
- Both LibreChat web search and Anthropic-native web search produce a
web_searchtool - When both are enabled, there should be only one
web_searchtool - LibreChat's definition should be preferred
- Unrelated tools and other providers should not be affected
Let me explore the repository structure first.
- Both LibreChat web search and Anthropic-native web search produce a
Assistant
Let me explore the structure more, especially looking for web_search related code and Anthropic-related code.
Assistant
Let me focus on the key files. Let me look at the Anthropic-related and tools-related source
Assistant
Let me look at the most relevant source files. Let me start with the agents/tools-related files and the Anthropic endpoint:
Assistant
Let me use the correct format for the open command.
Assistant
Let me look at the ToolService and the Anthropic-related agent spec files.
Assistant
Let me look at the key agent files and how tools are filtered for Anthropic.
Assistant
Let me focus on the Anthropic-specific files and the agent spec configurations
Assistant
Now I see the Anthropic-specific
web_searchtool is added ingetLLMConfig. Let me find where these tools get merged with LibreChat's toolAssistant
Let me look at how the Anthropic tools are combined in the agent initialization flow
Assistant
Let me look at the OpenAI config.ts that handles Anthropic passthrough and how tools are combined:
Assistant
Let me look at how tools are combined in the agent initialization:
Assistant
Now I can see the issue clearly. Let me look at where the tools get concatenated in
initialize.ts:Assistant
Let me just use the terminal to view the relevant section of the file.
Assistant
Now I understand the issue clearly. Let me look at the exact concatenation line:
Assistant
Let me also verify the exact structure of the Anthropic tool definition and understand how LibreChat tools are loaded
Assistant
Now I have a clear understanding of the issue:
options.toolscomes fromgetLLMConfig(Anthropic) and contains{ type: 'web_search_20250305', name: 'web_search' }structuredToolscomes from LibreChat's tool loading and also contains a tool namedweb_search- Line 846 does
structuredTools.concat(options.tools)creating duplicates when both are enabled
The fix is to deduplicate by name, preferring LibreChat's tool definitions. Let me also look at the tests to understand the expected
Assistant
Let me check what the LibreChat web_search tool definition
Assistant
Let me also look at how tools are loaded in
load.tsand the ToolService's `loadAgentToolsAssistant
Now I have a complete understanding of the issue. Let me implement the fix.
The issue is at line 846 in
packages/api/src/agents/initialize.ts:tools = structuredTools.concat(options.tools as GenericTool[]);When both LibreChat's web_search and Anthropic's native web_search are enabled, both
structuredToolsandoptions.toolscontain a tool namedweb_search, creating a duplicate that Anthropic rejects.The fix: deduplicate by tool name, preferring
structuredTools(LibreChat's definition) overoptions.tools(Anthropic'sAssistant
Now let me implement the fix:
Assistant
Let me use replace instead:
Assistant
Let me first open the file at the right line:
Assistant
Now let me apply the replace:
Assistant
Now let me check if there are other places where the same concatenation happens, particularly in the
@librechat/agentspackage:Assistant
Let me also check the
@librechat/agentspackage for any related tool deduplication. Let me look at the scripts that seem related:Assistant
Let me check the
@librechat/agentspackage for any existing deduplication logic:Assistant
Let me check the
loadAgentToolsfunction in ToolService.js to see if there's another place where tools could be duplicatedAssistant
Let me check the
loadAgentToolsfunction for any existing deduplication logicAssistant
Now let me run the relevant tests to verify my fix is
Assistant
Let me run the Anthropic LLM spec first
Assistant
Let me check how tests are run in this project
Assistant
Let me look for the test script:
Assistant
Let me run the packages/api tests
Assistant
Let me run the packages/api test suite to see if my change breaks
Assistant
Let me check if there's a specific test for the initialize agent functionality
Assistant
Let me run the specific test for agent
Assistant
The test failures are pre-existing module resolution issues (unrelated to my change). Let me verify my change compiles correctly using
Assistant
Let me check if any TS errors are specifically related to my change
Assistant
All pre-existing errors. Let me verify my change looks correct by viewing it
Assistant
Let me also check the Anthropic-related test and the edge case scripts in the agents
Assistant
Let me check if there's any existing deduplication logic in the agent tools handling
Assistant
Let me check if there's a similar concatenation happening in the CJS code path too
Assistant
Let me also verify there's no similar concatenation in the CJS ToolService
Assistant
Let me verify that the GenericTool type has a
nameAssistant
Let me check the GenericTool type definition
Assistant
Let me check the CJS client.js to see if there's any similar tool merge
Assistant
Let me do a final review of my change
Assistant
My change is exactly what's needed. Let me also write a quick verification script to make sure the logic is
Assistant
Let me write a test
Assistant
Let me test more edge cases
Assistant
All edge cases pass correctly. Let me clean up the temp files:
Assistant
Now let me go through the checklist:
Checklist
1. If an error was reported in the issue description, I have successfully reproduced it.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.