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 locating where web_search tools are defined for Anthropic and LibreChat.
- Assistant
I'll inspect the Anthropic endpoint and web_search tool handling next.
- Assistant
Let me look at the Anthropic llm.ts file more carefully, and also how tools are merged when both are present.
- Assistant
I'll read the web_search logic in llm.ts and search where tools get combined for Anthropic.
- Assistant
There's a note about tool deduplication in initialize.ts — I'll inspect that and the rest of Anthropic web_search setup.
- Assistant
The Anthropic path concatenates provider tools with structured tools — I'll inspect that and related web_search references.
- Assistant
I'll compare how OpenAI and Anthropic merge native tools with LibreChat tools when both include web_search.
- Assistant
I'll check initialize tests and recent diffs related to Anthropic tool merging.
- Assistant
I'll inspect initialize tests for tool-conflict handling and where Anthropic receives tools.
- Assistant
I'll inspect LibreChat's web_search tool shape and where those merged tools are consumed.
- Assistant
I need to understand what shape Anthropic/native web search tools have vs LibreChat tools. The LibreChat tools are structured tools (LangChain style) with a
.nameproperty. Anthropic native tools ha... - Assistant
I'll check non-agent tool handling and how run.ts combines tools with toolDefinitions.
- Assistant
Let me look at how tools and toolDefinitions interact when creating the Anthropic client. The native Anthropic web_search is added as options.tools from getLLMConfig. When agent has LibreChat web_sear...
- Assistant
Let me look at how @librechat/agents handles tools when sending to Anthropic - specifically looking for web_search duplicate issues.
- Assistant
I'll inspect how Graph merges tools and how Anthropic binds native web_search.
- Assistant
I'll check how event-driven mode loads web_search and merges it with Anthropic's native tool.
- Assistant
Let me look at formatStructuredToolToAnthropic and how tools get bound - particularly native web_search tools.
- Assistant
Let me read the tools.mjs for anthropic.
- Assistant
Let me find formatStructuredToolToAnthropic definition
- Assistant
Let me see the formatStructuredToolToAnthropic function
- Assistant
I'll trace where tools are bound to the model during a run.
- Assistant
There's
getToolsForBinding- that's key! - Assistant
Let me read getToolsForBinding in AgentContext.mjs
- Assistant
I'll find how agent.tools and graphTools get into AgentContext.
- Assistant
I'll check imports in initialize.ts and look for existing tests or related helper utilities.
- Assistant
I'll inspect what loadToolDefinitionsWrapper returns for tools/structuredTools.
- Assistant
Let me read the return at line 883
- Assistant
I'll also check the non-agent Anthropic path for the same tools merge issue.
- Assistant
I'll implement Anthropic-specific filtering in initialize.ts so LibreChat's web_search wins over the native tool.
- Assistant
Applying the Anthropic web_search preference logic in
initialize.ts. - Assistant
I'll verify the change with a focused test, then run the existing initialize tests.
- Assistant
I'll add a temporary verification script modeled on the initialize tests.
- Assistant
I'll create a temporary verification test based on the existing initialize test helpers.
- Assistant
I'll create a temporary test outside the normal path or use a manual script. The jest config ignores
manual.spec- so I can create a temp file and run it with jest without putting it as a permanent ... - Assistant
The create command didn't write the full content — I'll write the file via the shell instead.
- Assistant
Running the temporary manual test.
- Assistant
I'll rename the temp file so Jest's ignore pattern doesn't exclude it.
- Assistant
Need to check how other tests resolve librechat-data-provider Jake.
- Assistant
data-provider may need building — I'll check whether initialize.test.ts runs successfully.
- Assistant
dist is missing for data-provider. Let me check node_modules for the package.
- Assistant
The data-provider package has no dist. Need to build it.
- Assistant
Build seemed to complete silently. Let me check dist and also build data-schemas if needed, then run the test.
- Assistant
Need to build data-schemas too. Or maybe I should just run the existing initialize.test which currently passes somehow - how?
- Assistant
OK let's try the test again
- Assistant
All four verification cases passed. Next I'll run the existing initialize tests and clean up the temp file.
- Assistant
All 34 existing tests passed. I'll check types and review the final diff.
- Assistant
Unrelated package files were modified — I'll check and restore them.
- Assistant
Those package.json changes were accidental — restoring them.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.