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 trace where provider and LibreChat tools are assembled, identify the Anthropic-specific path, and locate relevant tests before making a narrowly scoped deduplication change. First I’ll inspect the repository structure and search for
web_searchhandling. - Assistant
rgis unavailable, so I’ll use recursivegrepwith dependency/build directories excluded to find the tool definitions and assembly logic. - Assistant
The likely collision is in
packages/api/src/endpoints/anthropic/llm.ts, where native search is appended to an existing tools array that can already contain LibreChat’s function tool. I’ll inspect that implementation, its type context, and the Anthropic tests around tool handling. - Assistant
The output confirms native search is generated in this config function, but I need the final merge section and the option/result types to distinguish LibreChat function tools from Anthropic-native tool objects safely.
- Assistant
getLLMConfigreturns only provider-generated tools, so the duplicate likely appears when those are combined with request tools in the shared OpenAI-compatible config. I’ll inspect that merge and the endpoint option types/callers to ensure the fix applies only to Anthropic. - Assistant
The endpoint config’s
toolsare later combined with dynamically loaded LibreChat tools during client initialization. I’ll inspect Anthropic and OpenAI initialization side-by-side, plus tool conversion code, to reproduce the exact duplicate shape and choose the narrowest merge point. - Assistant
Initialization returns native tools separately; client construction must append loaded tools. I’ll trace
InitializeResultBaseconsumers and spread/concat operations involvingtools, including the API application layer. - Assistant
The concrete merge is
structuredTools.concat(options.tools)in agent initialization. I’ll inspect that block and its tests/mocks; this is where LibreChat tools (first) and provider-native tools (second) meet, and where preserving LibreChat’s definition can be implemented without affecting non-Anthropic providers. - Assistant
The merge currently blindly appends Anthropic’s
{ type: 'web_search_20250305', name: 'web_search' }after LibreChat’s structuredweb_searchtool. The safe fix is at this merge: only for Anthropic, and only when a structured LibreChat tool namedweb_searchexists, filter the exact Anthropic-native web-search definition while retaining all other provider tools. I’ll review imports/types and nearby merge-focused tests before editing. - Assistant
One edge case is event-driven tool loading:
toolDefinitionsmay identify LibreChat web search even ifstructuredToolsis empty. Before changing the merge, I’ll inspect how both outputs are populated and ultimately returned so deduplication detects LibreChat’s tool in every supported execution mode without accidentally suppressing native search when LibreChat search is unavailable. - Assistant
I need the omitted loader result destructuring to verify whether a loaded LibreChat tool always appears in
structuredToolsas well astoolDefinitions. - Assistant
Both representations can signal a successfully loaded LibreChat tool, so the dedupe should check
structuredToolsandtoolDefinitions. I’ll introduce an Anthropic-only provider-tool filter immediately before the existing merge: if LibreChatweb_searchloaded, remove only provider tools namedweb_search; all unrelated tools and all other providers retain current behavior. - Assistant
Python is unavailable, and the attempted edit made no source change. The repository already shows package manifest modifications that I did not create; I’ll inspect those diffs to determine whether they are pre-existing/unrelated, then use the repository’s Node runtime for the targeted source edit.
- Assistant
The source change is in place. The manifest diffs are unrelated to this work (the lockfile shows broad dependency pruning despite no install command); I’ll inspect
package.json’s exact change and avoid including unrelated modifications. Next I’ll run formatting/type checks and the focused agent initialization test suite, which should also catchGenericTool.nametyping issues. - Assistant
The root has no
testscript; tests are scoped to@librechat/api. I’ll invoke that workspace’s Jest directly in CI/non-watch mode and run ESLint on the changed file. I’ll also restore only the unrelated root manifests to HEAD, since they were not part of the fix and must not be submitted. - Assistant
ESLint passes. Jest cannot resolve the internal
librechat-data-providerpackage because its build output/symlink is absent, an environment setup issue rather than a test failure. I’ll inspect workspace scripts and package layout, build the required internal dependency, then rerun the focused tests. - Assistant
I’ll build
packages/data-providerusing the existing script, verify that it does not modify tracked sources/manifests, and rerun the same tests. - Assistant
The first internal dependency now resolves; Jest next reports the other unbuilt workspace,
@librechat/data-schemas. I’ll build that package and rerun. - Assistant
All 153 focused tests pass, including agent initialization and both direct/compatible Anthropic config suites. To validate compilation and bundling, I’ll build
packages/api; then I’ll inspect the final diff and consider whether the merge guard covers every relevant tool shape while preserving unrelated tools/providers. - Assistant
The API build succeeds and the diff is limited to one source file. As a final correctness check, I’ll inspect production
loadToolsreturn behavior and provider constants to confirm the guard sees LibreChat search and triggers for both native Anthropic initialization paths. - Assistant
The provider values match (
anthropic). I’ll inspectloadAgentToolsaround its return to ensure loaded web search is represented by a named structured tool as expected. - Assistant
Legacy loading definitely returns a named structured web-search tool. Definitions-only mode may return no structured instances, so I’ll inspect that wrapper’s return shape; if native and serialized tools are combined downstream, the dedupe may need to run even when
structuredToolsis empty rather than only inside the legacy merge branch. - Assistant
Production defaults to definitions-only mode, confirming an important edge case: LibreChat search can exist only in
toolDefinitions, while native search sits intools. The first edit’s filter was nested too late in the legacy-only merge branch. I’ll move provider filtering before initial tool selection so both definitions-only and legacy modes retain LibreChat search, while preserving unrelated provider tools. - Assistant
The logic now covers both representations: in definitions-only mode native search is removed from
toolswhile LibreChat search remains intoolDefinitions; in legacy mode LibreChat’s structured tool remains first and unrelated native/provider tools are appended. I’ll rerun lint, focused tests, and the API build after this refactor. - Assistant
Validation is clean: ESLint passes, all 153 focused tests pass, and the API package builds successfully. I’ll perform one final repository-status/diff check to ensure there are no generated or unrelated tracked changes before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →