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
I'll start by exploring the repository structure and searching for code related to web_search tools and Anthropic integration.
- Assistant
Let me search more specifically for web_search related code.
- Assistant
Hmm, no results? Let me try differently.
- Assistant
rg is not available, need to use grep.
- Assistant
I'll inspect the Anthropic LLM code and agent tool loading paths where duplicate
web_searchtools are likely defined. - Assistant
I'll examine how agents tools are built and how Anthropic handles
web_search. - Assistant
Next I'll inspect Anthropic LLM tool building and configs that could create a duplicate
web_search. - Assistant
I'll find where LLM config tools and agent tools are merged so we can detect the duplicate
web_searchpath. - Assistant
I'll dig into how tools are attached for Anthropic runs and where native vs LibreChat web search collide.
- Assistant
Checking git history and where Anthropic native tools merge with LibreChat tool defs.
- Assistant
I'll inspect run/initialize paths where LibreChat tools meet Anthropic native tools.
- Assistant
Let me look at how clientOptions.tools from llmConfig merge with agent tools. The tools from getLLMConfig for Anthropic are returned separately - probably put into llmConfig or options.tools.
- Assistant
There's also getAnthropicLLMConfig imported in openai config. Let me look at initialize.ts for anthropic and the openai config.
- Assistant
I'll track how LLM config tools get combined with the agent's tool list.
- Assistant
Let me look at initialize.ts around line 829 where tools are merged.
- Assistant
I'll inspect tool definitions and how the agents package sends tools to Anthropic.
- Assistant
Let me check how agent tools and native tools are combined in the @librechat/agents package.
- Assistant
Let me search in the agents package for how tools are sent to Anthropic.
- Assistant
There's a WebSearchToolName. Let me look at how tools are bound for Anthropic in the agents LLM layer.
- Assistant
Let me look at formatStructuredToolToAnthropic and how tools from clientOptions get merged. Also look at Graph.mjs for tool binding.
- Assistant
Let me look at llm/init.mjs and how tools are prepared before binding.
- Assistant
Looking at Graph.mjs around line 499-534 and 595-630, I need to understand how allTools is built.
- Assistant
Let me look at getToolsForBinding and agentContext setup
- Assistant
Looking at getToolsForBinding and more of AgentContext for how native tools work. The comment says "Creates schema-only tools from toolDefinitions for event-driven mode, merged with native tools"
- Assistant
I'll check what initializeAgent returns and how tools vs toolDefinitions are used.
- Assistant
I'll look for existing dedup patterns for OpenAI and similar web_search collision handling.
- Assistant
I'll check project docs and agent initialize tests for web_search / tools guidance.
- Assistant
There's a test around GOOGLE_TOOL_CONFLICT with options.tools. Let me read that part of the initialize test and also the optimize around native tools more carefully.
- Assistant
Confirming the web_search constant and how OpenAI native tools are shaped:
- Assistant
I'll inspect Anthropic tool formatting and schema-only tools, and any existing dedupe helpers.
- Assistant
Looking for formatStructuredToolToAnthropic in langchain's ChatAnthropic or in this package.
- Assistant
Let me look at formatStructuredToolToAnthropic in langchain anthropic.
- Assistant
I'll verify imports in
initialize.tsand the exact tool-merge block shape. - Assistant
I'll implement Anthropic-only deduping so LibreChat's
web_searchwins over the native tool. - Assistant
I'll inspect initialize test mocks and craft a quick verification script.
- Assistant
I'll write a temporary verification script and run the existing initialize tests.
- Assistant
Next I'll run the initialize agent tests to confirm nothing regressed.
- Assistant
I'll check the package test script and re-run without watch mode.
- Assistant
I'll use test:ci with a focused path pattern.
- Assistant
I'll build dependencies and re-run the initialize tests.
- Assistant
Checking whether librechat-data-provider is built and linked correctly.
- Assistant
I'll build data-provider and the api package, then re-run the tests.
- Assistant
Build seems done silently. Let me also check if data-schemas needs building and if.api node_modules resolve works.
- Assistant
The data-provider build might have failed silently. Let me try building again.
- Assistant
Good, both built. Now run tests again.
- Assistant
I'll run an integrated temporary test exercising
initializeAgentfor the Anthropicweb_searchduplicate case. - Assistant
All tests passed. Removing the temporary test file and cleaning up.
- Assistant
There are unexpected changes to package-lock.json and package.json - I should not submitthose. Let mecheck what happened.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.