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 understand the issue:
- When both LibreChat web search and Anthropic-native web search are enabled, there are duplicate
web_searchtool names - Anthropic rejects duplicate tool names
- The fix should: expose one
web_searchtool and prefer LibreChat's definition - Don't affect unrelated tools or other providers
Let me explore the repository structure to understand how the codebase works and find relevant files.
- When both LibreChat web search and Anthropic-native web search are enabled, there are duplicate
Assistant
Let me search for files related to Anthropic and web_search tool to understand the codebase structure better.
Assistant
Let me look at the critical files. First, let me check the Anthropic-related code and tool handling.
Assistant
Now let me look at how tools are loaded/aggregated for agents.
Assistant
Let me look at the ToolService and the key tool
Assistant
Let me trace the flow - how tools from
getLLMConfig(Anthropic-native web_search) and LibreChat's web_search get mergedAssistant
Let me look at the key files for tool merging:
Assistant
Let me look at
api/server/controllers/agents/v1.jsto see how tools from different sources are merged.Assistant
Let me look at
packages/api/src/agents/initialize.tsand see how tools fromgetLLMConfigare merged with LibreChat's toolsAssistant
Let me look at
packages/api/src/agents/initialize.tsaround line 846 to see how tools are combined. Also, let me see howAssistant
I need to invoke the tool. Let me look at the initialize.ts file.
Assistant
Now I can see the key section. Let me look more at what
options.toolscomes from and how the merge worksAssistant
Let me look at the full context around the tool merge area (lines 820-850) in initialize.ts:
Assistant
Now I understand the issue. Let me look at where else Anthropic-native tools might get merged with LibreChat tools to check all locations.
Assistant
Let me check what
Tools.web_searchresolves to and look at the tool loading path for LibreChat's web searchAssistant
Let me look at the
Toolsenum to understand the value.Assistant
The
web_searchvalue might be from theToolsenum or another constant. Let me look at the Tools definition.Assistant
Let me check if OpenAI also has a similar issue - how OpenAI's LLM config returns tools.
Assistant
Now I have a clear understanding of the issue. Let me look at the exact merge logic and implement the fix.
Assistant
Let me check the existing test files for this area of code:
Assistant
Let me look at the initialize test file to understand the test patterns.
Assistant
Let me search for Anthropic-specific tests in the initialize test file.
Assistant
Let me search for Anthropic-related tests more broadly in the test files
Assistant
Let me look at
packages/api/src/agents/handlers.spec.tsandpackages/api/src/agents/tools.spec.tsfor relevant tests.Assistant
Let me now implement the fix. Let me first create a simple script to reproduce the issue.Let me first check how the
getLLMConfigis structured for both Anthropic and OpenAI to understand the patterns betterAssistant
Let me view the full context around the tools section in
anthropic/llm.tsAssistant
Let me check if there's a similar merge happening elsewhere, especially in `run.ts
Assistant
Now I understand the issue fully. Let me implement the fix. The key insight:
- In
initialize.ts, when bothoptions.tools(fromgetLLMConfig- containing Anthropic's nativeweb_search) andstructuredTools(LibreChat's tools, includingweb_search) exist, they're concatenated - This creates duplicate
web_searchtool names, which Anthropic rejects - Fix: Filter out Anthropic-native tools whose names already exist in
structuredToolsbefore concatenation
Let me first run the existing tests to see the baseline:
- In
Assistant
Let me check how tests are configured in the project
Assistant
Let me check the package.json for test configuration.
Assistant
Let me check the jest config.
Assistant
Let me check the
GenericTooltype to make sure it has anameproperty.Assistant
Let me check the GenericTool definition.
Assistant
Now I'm confident about the fix. Let me implement it.
Assistant
Let me go to the exact location I need to edit.
Assistant
Now I'll implement the fix. The change replaces the simple
concatwith a deduplication step for Anthropic, filtering out any Anthropic-native tools whose names already exist in LibreChat's structured toolsAssistant
The edit looks good. Let me verify the full modified section looks correct.
Assistant
Let me check the diff to confirm the change is clean
Assistant
Now let me also check if there are other places where Anthropic-native tools could be merged with LibreChat tools
Assistant
Let me look at the
loadAgentToolsfunction to check if it also deals with tool mergingAssistant
Let me now try to run the initialize tests to make sure my change doesn't break anything. Let me first check how to run tests properly for this project.
Assistant
Let me try with the correct flag name.
Assistant
The test failures are due to module resolution (monorepo needs build), not related to my change. Let me verify the TypeScript compiles at least.
Assistant
The errors are all from the monorepo's module linking, not from my code. Let me do a quick syntax check on just my file to make sure there are no syntax errors.
Assistant
Let me also verify the OpenAI tool structure to make sure my fix is complete.
Assistant
Let me see the full context of the OpenAI tool push
Assistant
Let me also verify there are no other places where Anthropic-native tools merge with LibreChat tools.
Assistant
Let me trace how
optionsobjects are created to make sure I've covered all paths.Assistant
Let me search more broadly for where Anthropic tools are returned from config
Assistant
Let me write a quick verification script to simulate the deduplication behavior
Assistant
All edge cases pass correctly. Let me clean up the temp file.
Assistant
Let me do a final review of the change
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.