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 Anthropic LLM code and how web_search tools are combined.
- Assistant
Let me look at agent tools loading and how tools are combined - particularly where duplicate web_search might occur.
- Assistant
Let me look at where Anthropic tools are assembled - particularly native web_search alongside agent tools, and the config.anthropic.spec.ts
- Assistant
I'll search where LLM config tools are merged with agent tools and any recent duplicate-handling changes.
- Assistant
There's a comment in initialize.ts about duplicate tools. Let me look at that and how tools are merged.
- Assistant
I found the likely merge point — Anthropic concatenates native and structured tools. I'll inspect that path and related Anthropic tool utilities next.
- Assistant
So when both options.tools (native Anthropic web_search) and structuredTools (LibreChat web_search) are present, they get concatenated. That would create two tools with the same name "web_search".
- Assistant
Looking at lines 839-847 more carefully, when both LibreChat structured tools and provider native tools exist, they are concatenated. For OpenAI, the native tool is
{ type: 'web_search' }without be... - Assistant
Let me look at how options.tools flows in and if there's an existing test for this case in initialize.test.ts. Also check git history or any PR branches related to this.
- Assistant
For event-driven mode they might use toolDefinitions instead of structuredTools - let's see how that case works and look at how the agent run uses tools vs toolDefinitions.
- Assistant
Let me look at how the agent package merges tools when binding to the model - specifically in run.ts
- Assistant
Looking at how tools are really assembled in the @librechat/agents package...
- Assistant
Let me look at Graph.mjs where tools are filtered and how tools are prepared for Anthropic.
- Assistant
Let me look at getToolsForBinding and AgentContext to understand how tools get merged and bound.
- Assistant
Let me look at getToolsForBinding and getEventDrivenToolsForBinding more carefully.
- Assistant
The cleanest fix looks like filtering the native Anthropic web_search when LibreChat already provides one. I'll confirm the tool name and how definitions are emitted.
- Assistant
I'll check how
getOptions/options.toolsare produced during agent initialization. - Assistant
I'll also check AGENTS.md/CLAUDE.md and any existing comments about this web_search collision.
- Assistant
I'll inspect the earlier toolDefinitions handling so the filter covers the event-driven path correctly.
- Assistant
Implementing Anthropic web_search dedup in
initialize.ts, preferring LibreChat's tool over the native one. - Assistant
I'll apply the edit to filter Anthropic native web_search when LibreChat has web_search.
- Assistant
I'll format the long line and run the related initialize tests.
- Assistant
I'll inspect the test helpers and run the initialize agent tests.
- Assistant
I'll add a temporary verification test, run it, then remove it—without changing the repo tests.
- Assistant
I'll write the temporary test with a heredoc instead.
- Assistant
Let me run the temporary test.
- Assistant
I'll check the Jest module mapping and whether packages need a build first.
- Assistant
We're still in packages/api - ls packages would start from packages/api
- Assistant
The data-provider package source might need building. Let me check if dist exists and how jest maps it.
- Assistant
Need to build data-provider. Let me check how initialize.test is normally run - maybe dist is expected to be built in root node_modules.
- Assistant
The data-provider package is linked but dist is missing. Need to build it.
- Assistant
Build finished. Also may need data-schemas and api packages. Let me try the test again.
- Assistant
Need to build data-schemas too.
- Assistant
Try tests again.
- Assistant
All temp tests passed. Now I'll run the existing initialize tests and delete the temp file.
- Assistant
I'll check whether non-agent chat paths also merge LibreChat and Anthropic native web_search tools.
- Assistant
The agent initialize path seems to be the main place. Verifying the final diff and cleanup.
- Assistant
Cleaning up the temp test and unintended package.json changes.
- Assistant
I'll wrap the long condition so it matches the project's formatting.
- Assistant
I'll re-run the initialize tests one last time before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.