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 and then find the relevant code related to 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 first.
Assistant
Let me search for relevant code related to
web_search, Anthropic, and tool definitionsAssistant
Let me look at the key source files related to this issue, particularly the Anthropic LLM handling and how tools are
Assistant
Let me look at the Anthropic LLM file to understand how web_search is handled.
Assistant
Let me just use cat to read the file.
Assistant
Now let me look at the config files that assemble tools, especially for Anthropic via OpenAI:
Assistant
Let me look at the main config file that aggregates tools:
Assistant
Let me look at the transform function:
Assistant
Let me search for where tools are merged or deduplicated:
Assistant
Let me look at the agents/tools loading flow and how tools are assembled
Assistant
Let me look at the agents/load.ts to understand how tools are loaded and where the LibreChat web_search tool and Anthropic-native web_search could collide.
Assistant
Let me look at how the tools from LLM config and the agent's tools are merged. Let me search for where they combine.
Assistant
Let me look at the initialize.ts to understand the complete tool loading flow.
Assistant
Let me look at
added.tsto understand howweb_searchgets into toolsAssistant
Let me understand the tool shapes better. Let me look at the tools definitions:
Assistant
Let me look at the specific merge logic in initialize.ts more carefully
Assistant
Let me look at lines 660-700 of initialize.ts to understand how structuredTools is generated
Assistant
Let me understand the full path of tool loading by looking at the
callLoadToolsfunction:Assistant
Let me look at lines 635-650 to see the callLoadTools function:
Assistant
Now I understand the issue. Let me look at lines 825-850 of initialize.ts more carefully
Assistant
Now I understand the issue. Let me create a script to reproduce the problem first, then implement the fix.
Let me first check how the tool names are compared by looking at a test:
Assistant
Let me check the test file for the merge
Assistant
Let me search for tests that cover the Anthropic/OpenAI merge path
Assistant
Let me check the GenericTool type to understand the shape:
Assistant
Let me check the GenericTool type definition
Assistant
Now let me also look at
StructuredToolInterfaceto understand whatnameproperty it has:Assistant
Now I have a clear understanding of the issue. Let me implement the fix.
The problem is in
packages/api/src/agents/initialize.tsat line 846. When bothstructuredTools(from loadTools, containing LibreChat'sweb_searchtool) andoptions.tools(from provider config, containing Anthropic's nativeweb_searchtool) exist, they are blindly concatenated, creating duplicate tool names. Anthropic rejects duplicate tool names.The fix: when concatenating, filter out tools from
options.toolswhose names already exist instructuredTools, so LibreChat's definitions take precedence.Assistant
Let me use the edit command to make the change
Assistant
Now let me make the fix. I'll replace the concat line with a deduplicated version:
Assistant
Let me try using sed to make the change directly
Assistant
Let me verify the change:
Assistant
Good. Now let me run the relevant tests to make sure the change doesn't break anything.
Assistant
Let me see the full error output:
Assistant
The test file seems to have a pre-existing babel issue. Let me check how the project runs tests:
Assistant
Let me try a different approach.
Assistant
Let me check the package.json for
Assistant
Let me check how the api tests work:
Assistant
Let me try running the tests from the packages/api directory
Assistant
Let me try running the test differently:
Assistant
Let me verify my TypeScript change is syntactically valid by checking the TypeScript compilation
Assistant
Let me also verify there isn't another code path where the duplicate issue could occur. Let me check how the Anthropic tools are used in the non-agent path:
Assistant
Let me check the Anthropic initialize.ts to understand the tool handling there
Assistant
Let me also check how the regular chat path handles tools, not just the agents path:
Assistant
Let me search for how tools flow from endpoints to the LLM call:
Assistant
Let me check how OpenAI tools flow through the server:
Assistant
Let me check the openai service to understand how tools are assembled when calling the LLM:
Assistant
Let me verify my change looks correct one more time and also check if there's a TypeScript issue:
Assistant
Let me also check how tools flow in the Anthropic endpoint directly (non-agent path):
Assistant
Let me check the Anthropic index.ts:
Assistant
Let me check if the regular (non-agent) chat path also merges tools similarly:
Assistant
Let me look for the main server endpoint handling
Assistant
Let me check if there's a server path that handles tools merging
Assistant
Let me check how tools are handled in the main API server:
Assistant
Let me ensure I haven't missed any other merge points by checking the broader tool concatenation:
Assistant
Let me check if transformToOpenAIConfig could add tools to the Anthropic path
Assistant
Let me try to run the Anthropic-specific tests:
Assistant
Let me try building the packages first
Assistant
Let me also build the data-schemas package:
Assistant
Now let me run the Anthropic tests again:
Assistant
Now let me try running the initialize tests
Assistant
Now let me also run the Anthropic config tests:
Assistant
Let me run a broader set of tests:
Assistant
Let me create a quick script to verify the fix logic works correctly:
Assistant
Let me also test edge cases
Assistant
Let me clean up and run a broader set of tests
Assistant
Let me run the OpenAI config tests and the tools tests:
Assistant
Let me also run the tools tests:
Assistant
Let me also run the OpenAI llm tests and the transform tests:
Assistant
Let me make a final review of the change:
Assistant
Let me revert the unintended changes to package.json and package-lock.json:
Assistant
Let me verify only my intended change remains
Assistant
Let me verify git status
Assistant
The fix is complete. Let me now submit the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.