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 first inspect the repository structure and search for Anthropic tool assembly and
web_searchdefinitions. This should reveal where provider-native and LibreChat tools are merged and what focused tests already exist. - Assistant
The initial search shows provider-native web search handling in endpoint configuration, while LibreChat’s tool is built in
ToolService. I’ll narrow this to Anthropic endpoint/client code and inspect package scripts so I can identify the exact merge point and appropriate test command. - Assistant
Anthropic’s config builder appends a native
{ type: 'web_search_20250305', name: 'web_search' }. The bug likely occurs whentoolsalready contains LibreChat’s structuredweb_searchtool. I’ll inspect the full function, its types, and existing tests around native tools to establish ordering and whether the builder is exclusively Anthropic-scoped. - Assistant
I need the untruncated tool assembly section and
AnthropicConfigOptionsdefinition. In particular, I’ll verify whetheroptions.toolsis passed directly and how function-style tools are represented, so duplicate detection can be precise (name only), preserve unrelated tools, and safely prefer the existing LibreChat definition. - Assistant
getLLMConfigdoes not receive LibreChat tools; it returns only native additions. Therefore deduplication cannot happen there because the conflict is only visible later. I’ll inspect the generic OpenAI-compatible configuration wrapper and agent/client initialization where returned native tools are concatenated with runtime tools, aiming to place the fix at an Anthropic-only merge boundary rather than globally filtering tools. - Assistant
The provider configuration’s
toolsarray is later surfaced alongside loaded agent tools. I’ll inspect the local agent initialization path and its tests, especially the provider-tools merge noted near line 1285. This is the likely location where both definitions become available and where provider identity can constrain the behavior. - Assistant
The merge is explicitly at
initialize.ts:829–846. I’ll inspect that block and surrounding provider normalization. The intended change should likely alter only the Anthropic merge branch: if loaded structured tools include a tool namedweb_search, omit only the Anthropic-native tool of that name while preserving order and all other entries. - Assistant
The current merge concatenates
structuredToolsbefore native tools for Anthropic, producing two objects namedweb_search. A precise fix is to filter the provider-native array only when (1) resolved provider is Anthropic and (2) a LibreChat structured tool hasname === 'web_search'; then concatenate as before. I’ll verifyGenericToolshapes and whether event-driventoolDefinitionscan also reach the LLM independently, to ensure duplicate detection covers both supported loading modes without accidentally removing the sole executable tool. - Assistant
Event-driven mode retains LibreChat tools in
toolDefinitionswhile native tools remain intools, so checking onlystructuredToolsmay miss the same name conflict. SincetoolDefinitionsare LibreChat’s serializable definitions and are executable through the registry, they should also count as LibreChat’s preferred definition. I’ll inspect graph/client binding to confirm both arrays are combined for provider calls and then implement a small local helper or inline predicate based on both sources. - Assistant
The initialized agent carries both fields into the graph. Even if one mode prefers definitions, duplicate avoidance should be based on either LibreChat representation because the issue’s invariant is one exposed name. I’ll inspect the exact graph construction to ensure filtering the native entry does not remove a required provider-only object in event-driven mode; if definitions are supplied to the model, filtering is correct.
- Assistant
The agents library explicitly “merges schema-only tools with native tools,” confirming that
toolDefinitionsmust be included in collision detection. I’ll inspect that merge’s semantics to ensure initialization-side filtering is the appropriate repository-owned fix and to identify the exact native tool representation. - Assistant
The confirmed model-binding path appends instance/native tools after schema tools without deduplication. I’ll now change only the agent initialization merge: derive Anthropic provider tools, remove provider entries named
web_searchwhen either loaded LibreChat representation has that name, and leave Google conflict behavior plus OpenAI/Azure and unrelated tools unchanged. This also preserves the LibreChat-first order in full-instance mode and relies ontoolDefinitionsin event-driven mode. - Assistant
The environment lacks Python, so no source change occurred (Prettier reported unchanged). I’ll apply the same targeted replacement with the repository’s Node.js runtime, format it, and inspect the diff.
- Assistant
The diff now implements the intended provider-scoped filter and preserves all existing merge gates. I’ll run the focused agent initialization suite; it exercises provider tool merging, event-driven definitions, and the Google conflict guard, so it should catch regressions in this block.
- Assistant
The focused suite could not start because the workspace dependency
librechat-data-providerhas not been built; this is an environment setup failure, not a test assertion. I’ll build the required workspace package (and API dependencies if needed), then rerun the suite. - Assistant
The missing data-provider workspace is now built successfully. I’ll rerun the focused initialization tests.
- Assistant
A second unbuilt workspace dependency,
@librechat/data-schemas, blocks module loading. I’ll build it and rerun; no source or test files are being changed by these builds. - Assistant
The focused suite passes all 34 tests, including provider merge and event-driven cases. I’ll now verify the concrete LibreChat search tool is indeed named
web_search, inspect git status for build artifacts, and run TypeScript/package build plus a targeted lint check. This will validate both the collision predicate and compile-time compatibility. - Assistant
Lint and API build passed, but
npmmodified rootpackage.jsonandpackage-lock.jsonas an unrelated workspace side effect. I’ll inspect those diffs, revert only those package-manager changes, and retain the source fix. I’ll also locatecreateSearchTool’s assigned name to complete the concrete name verification. - Assistant
The unrelated manifests are reverted; only the intended source file remains modified. The search implementation uses a
WebSearchToolNameconstant, so I’ll inspect that constant and then consider edge behavior in our initialization logic—especially an Anthropic-native array containing bothweb_searchand another native tool, and the event-driven case wherestructuredToolsis empty. - Assistant
The concrete tool constant is exactly
web_search, andgit diff --checkis clean. To reproduce and verify the actual merge—not merely a modeled array operation—I’ll check whether the built API exposesinitializeAgent. If it does, I can run a temporary standalone script with minimal mocks for Anthropic and compare duplicate-name behavior without adding or modifying repository tests. - Assistant
initializeAgentis exported from the built package, so I can exercise the real code path. I’ll create a temporary script under/tmp(not a repository test) using an Anthropic agent, nativeweb_search: true, and a mocked LibreChatweb_searchtool plus an unrelated tool. I’ll run it to verify exactly oneweb_searchremains and the unrelated tool survives, then remove the script. - Assistant
The real fixed initialization path returned
["web_search","calculator"]with one web search, confirming both preference and preservation. To satisfy the reported-error reproduction rigorously, I’ll temporarily save the source fix, restore onlyinitialize.tsto its committed pre-fix version, rebuild and run the same standalone scenario to observe the duplicate count, then immediately restore the fixed source and rebuild. These temporary build outputs are ignored and no tests/source beyond the target file will remain altered. - Assistant
The pre-fix real path reproduced the issue exactly:
["web_search","calculator","web_search"]and a duplicate count of 2. The fixed source and build are restored. I’ll run one final standalone event-driven scenario to verify that a LibreChatweb_searchintoolDefinitionsalso suppresses the native duplicate while retaining all LibreChat definitions, then rerun the focused suite against the restored final code and inspect the final diff/status. - Assistant
Implementation and verification are complete:
- [x] Reproduced the reported error. Using the real built
initializeAgentpath with pre-fix source produced["web_search","calculator","web_search"], confirming twoweb_searchtools. - [x] Confirmed the fix resolves the error. The same real path with the fix produced
["web_search","calculator"]and exactly one web search, preferring LibreChat’s tool. - [x] Considered edge cases. The filter is restricted to resolved Anthropic providers, removes only provider tools named
web_search, preserves unrelated tools, leaves other providers unchanged, and handles both full structured tools and event-driventoolDefinitions. The event-driven verification retained["web_search","calculator"]definitions and removed the conflicting native entry. - [x] Ran affected existing tests.
src/agents/__tests__/initialize.test.tspassed all 34 tests. Targeted ESLint passed, the API package built successfully, andgit diff --checkis clean. - No tests were added or modified. Only
packages/api/src/agents/initialize.tsis changed.
- [x] Reproduced the reported error. Using the real built
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.