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 repository structure and the issue. The issue is about Anthropic rejecting duplicate
web_searchtool names when both LibreChat web search and Anthropic-native web search are both enabled. The fix should expose oneweb_searchtool and prefer LibreChat's definition, without affecting unrelated tools or other providers.Let me explore the repository structure first.
Assistant
Let me search for files related to web_search and Anthropic tools.
Assistant
Let me look at the Anthropic LLM file and related tool handling, as the issue is about Anthropic rejecting duplicate
web_searchtool names.Assistant
Now I can see the issue. The
getLLMConfigfunction always pushes aweb_searchtool when enabled. Let me look at how these tools are merged with LibreChat's web search tools.Assistant
Let me trace where the
toolsfromgetLLMConfigare used and potentially merged.Assistant
Let me look at how the Anthropic config is used in
initialize.tsandconfig.ts:Assistant
Now let's look at
packages/api/src/endpoints/openai/config.tsto see how tools are mergedAssistant
Let me trace where
getOpenAIConfigis used and how tools are combined:Assistant
Let me look at where the tools are combined more broadly. The issue is about duplicate
web_searchtools. Let me search for whereweb_searchtools are defined (LibreChat's own web search tool) and where they get combined with Anthropic's tools.Assistant
Let me look at how tools are loaded and merged:
Assistant
Let me look at how
initialize.tsfor agents uses the tools from the config and combines them:Assistant
Let me check what
Tools.web_searchresolves to and understand the exact tool definitionsAssistant
Let me look at the tool definitions and understand the structure
Assistant
Let me look at the
GenericTooltype and itsnameproperty.Assistant
Now let me look at the exact concatenation logic in
initialize.ts:Assistant
Let me just grep the specific section of the code.
Assistant
Let me find the exact lines around the concatenation.
Assistant
Let me look at the full context around lines 825-855
Assistant
Let me check how to access the name property of a tool
Assistant
Let me find the correct path for langchain tool types.
Assistant
Let me check
StructuredToolInterfaceto see if it has anameproperty.Assistant
Let me look at the tools types file more directly.
Assistant
Now I have a good understanding of the issue. Let me look at the
Toolsenum to see the value ofTools.web_searchAssistant
Let me look at how the LibreChat web_search tool is defined:
Assistant
Let me look at how tool names (strings like
'web_search') get converted into actual tool instances. Let me checktools.tsin agentsAssistant
Let me look at how
loadToolsworks - how the string tool names get converted into actual tool instances. Let me check theadded.tsfileAssistant
Let me check if
Toolsis already imported ininitialize.tsAssistant
Now I have all the information I need. Let me implement the fix. The issue is clear:
- When LibreChat web search is enabled,
Tools.web_search(string'web_search') is added to the agent's tools - When Anthropic-native web search is enabled,
getLLMConfigreturns{ type: 'web_search_20250305', name: 'web_search' }inoptions.tools - These get concatenated in
initializeAgent, creating duplicateweb_searchtools that Anthropic rejects
The fix: In
initializeAgent, when the provider is Anthropic and bothoptions.toolsandstructuredToolshave items, filter out Anthropic's nativeweb_searchfromoptions.toolsif LibreChat'sweb_searchis already present instructuredTools.- When LibreChat web search is enabled,
Assistant
Let me use
replacecommand instead.Assistant
Let me open the file at the right location first
Assistant
Let me just use sed to view the lines, then use replace properly.
Assistant
Now let me apply the fix with the exact text formatting
Assistant
Let me try using the heredoc syntax
Assistant
Let me try using
gotofirst, then edit.Assistant
Now let me edit lines 839-847
Assistant
Let me try using heredoc for
editAssistant
The edit is applied. Let me verify the change and then run tests to make sure nothing is broken.
Assistant
Good. Now let me run the relevant tests to verify nothing is broken:
Assistant
Let me use the correct jest syntax
Assistant
Let me check the project's test configuration to run
Assistant
Let me check the package.json for test scripts
Assistant
Let me try with grep directly.
Assistant
Let me check how the packages/api tests run
Assistant
Let me try to run the specific test for initialize
Assistant
The test failures are due to module resolution issues unrelated to my change. Let me verify my change is correct by looking at the git diff:
Assistant
Let me verify the type of
RunnableToolLiketo make sure it hasnameAssistant
Let me verify TypeScript compilation for the changed file:
Assistant
Let me verify the OpenAI web_search tool also has a name property
Assistant
The file path is different. Let me check again.
Assistant
Let me check how the transform handles Anthropic tools
Assistant
Let me check how
overrideProvideris determined for Anthropic endpointsAssistant
Let me check the correct path.
Assistant
Let me check the provider config to see how Anthropic maps
Assistant
Let me check what
Providers.ANTHROPICresolves toAssistant
Let me find where
Providersis defined.Assistant
Let me check where @librechat/agents is
Assistant
Let me just search for the Providers
Assistant
Let me check where the @librechat/agents module actually
Assistant
Let me find where Providers.ANTHROPIC is defined
Assistant
My change looks correct. Let me now think about whether there are any additional edge cases to consider.
Let me verify one more thing - the
EModelEndpoint.anthropicvalue used for comparisonAssistant
Let me verify the complete change one more time
Assistant
Let me also check the AGENTS.md for any additional context
Assistant
Let me check CLAUDE.md for any context
Assistant
Let me do a final check to ensure there aren't other places where the duplicate web_search issue could occur
Assistant
Let me check the legacy.ts path briefly to see if there's a similar issue there
Assistant
The fix is in the right place and correctly handles the issue. Let me now submit.
Assistant
My fix looks good. Let me summarize what I did and submit:
Summary
Problem: When both LibreChat web search and Anthropic-native web search are enabled, the
initializeAgentfunction concatenatesstructuredTools(containing LibreChat'sweb_searchtool) withoptions.tools(containing Anthropic's nativeweb_searchtool{ type: 'web_search_20250305', name: 'web_search' }). This creates duplicateweb_searchtools, which Anthropic rejects.Fix: In
packages/api/src/agents/initialize.ts, before concatenatingoptions.toolswithstructuredTools, check if the provider is Anthropic and if LibreChat'sweb_searchis already present instructuredTools. If so, filter out Anthropic's nativeweb_searchfromoptions.tools, preferring LibreChat's definition. The fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.