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 locate the provider/tool assembly code and relevant tests, reproduce how duplicate
web_searchentries arise, then apply a narrowly scoped Anthropic-only deduplication that preserves LibreChat’s tool and verify focused plus broader tests.Checklist status will be reported before submission. First I’ll inspect the repository structure and search for Anthropic/web-search tool construction.
- Assistant
rgis unavailable, so I’ll usegrepto identify definitions and assembly points, excluding dependencies and generated directories. - Assistant
The likely collision is in
packages/api/src/endpoints/anthropic/llm.ts: it appends Anthropic’s native{ type: ..., name: 'web_search' }to caller-provided tools, where LibreChat’s function tool may already use that name. I’ll inspect that implementation, its config wrapper/export path, and existing Anthropic tests to choose the smallest provider-specific fix. - Assistant
The first output truncated the exact tool merge. I’ll inspect that range and the
AnthropicConfigOptionstype to establish whether caller tools can be Anthropic-native, OpenAI-style, or LangChain tool objects and how names are represented. - Assistant
getLLMConfigonly returns newly generated native tools; the duplicate must occur where these are combined with LibreChat tools. I’ll trace calls togetLLMConfigand inspect the common endpoint initialization logic so preference can be implemented where both definitions are visible, without changing native-search generation itself. - Assistant
I’ll inspect Anthropic initialization and the OpenAI-compatible Anthropic path, since both may combine generated native tools with runtime tools and both should obey the provider-specific behavior.
- Assistant
The initializer returns native tools separately; runtime assembly likely concatenates them with
handleToolsoutput. I’ll traceinitializeAnthropicand genericresult.toolsconsumption across API/client setup. - Assistant
Search patterns missed destructuring. I’ll inspect provider dispatch and references to its exported initialization function/type.
- Assistant
The agent initialization path is the key. I’ll inspect where provider-returned
toolsare merged with loaded LibreChat tools, including provider identity at that point. - Assistant
The collision is reproduced directly in code: for Anthropic,
structuredTools.concat(options.tools)retains both the LibreChatweb_searchtool and Anthropic’s nativename: 'web_search'. The fix belongs in this Anthropic-only merge branch: omit the native search definition when a LibreChat structured tool with that name exists, preserving order and every unrelated tool.Before editing, I’ll inspect
GenericToolshapes and nearby test infrastructure forinitializeAgent, so the name check handles actual runtime tools robustly and can be verified without changing tests. - Assistant
I’ll read the SDK’s
GenericTooldefinition and the rest of the existing initialization tests to decide whether direct.nameis sufficient and identify a suitable existing test command. - Assistant
GenericToolcarries a.name, and Anthropic native tool descriptors also expose.name. I’ll inspect the nearby tool-merging tests and then implement a concise filter only in the existing Anthropic merge case. The filter will activate only when the loaded LibreChat tool list containsweb_search, and will remove only provider tools namedweb_search; native-only search, unrelated native tools, OpenAI/Azure behavior, and all other providers remain unchanged. - Assistant
A definitions-only runtime can represent LibreChat tools in
toolDefinitionseven whenstructuredToolsis empty, so I’ll account for both representations. I’ll normalize only Anthropic’s provider-tool list before the existing selection/concatenation logic; this ensures the fix also covers event-driven mode while preserving Google conflict handling and other provider behavior. - Assistant
Python is not installed; no changes were made. I’ll apply the same exact replacement with a noninteractive Node script.
- Assistant
The implementation now handles both full-instance and definitions-only LibreChat tools, removes only Anthropic provider descriptors named
web_search, and leaves all unrelated tools intact. I’ll run formatting/type/build validation and the focused agent initialization suite; this suite exercises the surrounding provider merge and Google conflict logic, which guards against unintended cross-provider changes. - Assistant
Formatting passes. The focused suite cannot resolve the workspace package
librechat-data-provider, indicating its build artifact is absent rather than a test failure. I’ll inspect workspace package state, build the required local dependencies/API as the repository scripts expect, then rerun the suite. - Assistant
The missing workspace artifacts are now built successfully. I’ll rerun the focused suite and then build
packages/apito perform full TypeScript/Rollup validation of the changed code. - Assistant
Focused initialization tests (34/34) and the API build pass. To verify edge cases around the fix, I’ll also run Anthropic’s native configuration suites: they confirm native-only
web_searchgeneration remains unchanged for direct Anthropic and Anthropic-compatible custom endpoints. Then I’ll lint the changed file and review the final diff/status, distinguishing pre-existing package manifest changes from this fix. - Assistant
All 119 Anthropic configuration tests pass, lint is clean, and
git diff --checkreports no whitespace errors. The manifest changes were already present before my source edit and are unrelated; I won’t alter them.One final design review: the condition is Anthropic-only, checks both runtime and event-driven LibreChat definitions, preserves native search when LibreChat search is absent, and filters only the colliding provider tool while retaining unrelated provider tools. I’ll inspect the exact manifest diff only to ensure the build commands did not add further modifications, then report the requested checklist and submit.
- Assistant
Final checklist:
- Successfully reproduced the reported error condition. I traced the deterministic pre-fix path: Anthropic configuration emits
{ type: 'web_search_20250305', name: 'web_search' }, while agent initialization concatenated it with the loaded LibreChatweb_searchtool without name conflict handling. That produces the duplicate names Anthropic rejects. - Confirmed the fix resolves the error condition. The Anthropic-only merge now detects LibreChat
web_searchin either structured tools or event-driven tool definitions and removes the colliding provider descriptor, leaving LibreChat’s definition as the single exposed tool. - Considered edge cases. Native-only Anthropic search remains available; unrelated provider and LibreChat tools are preserved; definitions-only mode is handled; OpenAI, Azure, Google/Vertex, and other providers are unchanged.
- Successfully reproduced the reported error condition. I traced the deterministic pre-fix path: Anthropic configuration emits
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.