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 Anthropic tool assembly path and existing web-search definitions/tests, then reproduce the duplicate-name output before making the narrowest provider-specific fix.
- Assistant
rgis unavailable, so I’ll use recursivegrepwhile excluding dependencies and generated artifacts to identify where tool lists are merged and transformed for Anthropic. - Assistant
The native Anthropic definition is created in
packages/api/src/endpoints/anthropic/llm.ts; I’ll inspect that implementation and the agent/tool binding flow to determine where LibreChat’s function tool and the native server tool become adjacent duplicates. - Assistant
The endpoint config returns the Anthropic-native server tool separately from agent
toolDefinitions, so duplication likely occurs when the model client combines configured native tools with bound LibreChat tools. I’ll inspect the remainder of config and the Anthropic client implementation in the workspace package. - Assistant
@librechat/agentsis an installed/internal dependency rather than a source workspace here. I’ll inspect its client code and, more importantly, callers ofgetLLMConfigto find a repository-owned merge point where provider identity and both tool sets are available. - Assistant
The prior resolution command failed only because the package blocks
package.jsonexports. I’ll inspect the known directory directly, plus Anthropic initialization and the generic agent initialization that receives endpoint-nativeoptions.tools. - Assistant
For Anthropic, native tools are stored in
initializedAgent.tools, while LibreChat web search can be in either structured tools or event-driventoolDefinitions. The current merge only handles structured tools, and does not resolve same-name collisions. I’ll inspect the Anthropic formatter and tool-loading sections to verify tool shapes and choose a fix that covers both execution modes without touching other providers. - Assistant
The graph binds
agentContext.getToolsForBinding(), which is the decisive outgoing tool list. I’ll inspect howgraphTools(native tools) and schema definitions are combined, then implement filtering upstream ininitializeAgentso Anthropic receives LibreChatweb_searchand all unrelated native/LibreChat tools remain unchanged. - Assistant
getToolsForBindingappends nativegraphToolsafter LibreChat definitions, creating the duplicate. Since initializedtoolsultimately become graph tools (or otherwise are included), the safest narrow fix is: only forProviders.ANTHROPIC, if a loaded LibreChat tool namedweb_searchexists, remove the endpoint-native{name: 'web_search'}fromoptions.toolsbefore merging. I’ll confirm how initialized tools map into context and design a small exported/internal helper if needed for direct testing. - Assistant
The package’s binding method confirms the exact duplicate list. I’ll inspect
run.tsto distinguish normal tools fromgraphTools; then I’ll patchinitializeAgentat the merge point using tool-name detection that handles structured instances and serializable definitions. - Assistant
A key ordering detail is that provider overrides are applied after tools load but before this merge. I’ll inspect that segment to ensure the condition uses the effective
agent.provider(Anthropic) rather than the originally requested provider, then apply the narrowly scoped filter. - Assistant
There are pre-existing root package-file modifications unrelated to this issue; I’ll leave them untouched and verify their diff before editing only
packages/api/src/agents/initialize.ts. The effective provider is finalized before the merge, soagent.provider === Providers.ANTHROPICis appropriate and excludes Anthropic-compatible custom providers unless they explicitly resolve to Anthropic. - Assistant
Python is unavailable, so no source edit occurred. I’ll use the repository’s
editcommand. The provider-specific filtering will happen after Google’s unchanged conflict check, and Anthropic’s merge will use the filtered list; this avoids accidentally altering Google/OpenAI/Azure behavior. - Assistant
The line-range edit exposed two issues on review: it duplicated the existing comment and unintentionally removed the
agent.model_parametersassignment. I’ll restore that assignment exactly and remove the duplicate comment before testing. - Assistant
The insertion command retained the original merge line and added a duplicate. I’ll remove the duplicate and restore the original blank line after the configuration block, then run formatting/type checks.
- Assistant
The second edit similarly duplicated the following
ifline because replacement boundaries included only the brace. I’ll remove one duplicate, then re-run checks. - Assistant
Formatting and diff checks pass. The repository-wide TypeScript check is blocked by unresolved internal workspace package builds and many pre-existing errors, not this change. I’ll run the existing targeted
initializeAgentsuite, which directly exercises this merge path, and inspect its fixtures to see whether a temporary reproduction can invoke the function without modifying tests. - Assistant
The targeted suite is also blocked because workspace build artifacts (
librechat-data-provider) are absent. I’ll build the two missing internal packages using existing scripts, then rerun the suite. I’ll also review the current suite’s mock helper so I can reproduce both event-driven and structured-tool collision branches via a temporary script if practical. - Assistant
I’ll build
data-provideranddata-schemasonly (not the entire application), then rerun the focused suite. These builds generate ignored artifacts and should not alter submitted source. - Assistant
The focused suite passes all 34 tests after building dependencies. I’ll now run TypeScript again with workspace artifacts present and specifically inspect any errors in
initialize.ts. I’ll also use the installed AgentContext directly in a temporary/tmpscript to demonstrate the reported duplicate outgoing names from the pre-fix combination (LibreChat definition plus Anthropic native tool), without adding or changing repository tests. - Assistant
The temporary reproduction confirms the exact failure:
["web_search","web_search"]. TypeScript found one issue because endpoint-native tool elements are typed asunknown; I’ll fix that with a local shape assertion and rename the filtered list toproviderToolsfor clarity, then rerun type checking and tests. - Assistant
The literal replacement tool preserved
\\ncharacters instead of interpreting them. I’ll replace that single malformed line using a proper heredoc edit, then rerun all checks. - Assistant
The fix now type-checks cleanly and all targeted tests pass. Edge-case review: Anthropic keeps every provider-native tool except same-named
web_search; if native search is the only provider tool, LibreChat’s structured/definition path remains; OpenAI, Azure, Google, Vertex, and custom providers see the original list unchanged. I’ll remove unrelated pre-existing package manifest/lockfile changes from the submission and review the final diff. - Assistant
The final diff is a single provider-specific merge change. As an additional regression check, I’ll run the existing Anthropic endpoint configuration suite to ensure native web-search creation remains intact when LibreChat web search is absent.
- Assistant
I’ll perform one final temporary end-to-end list check using the same collision rule before AgentContext binding: it should retain an unrelated Anthropic-native tool, retain LibreChat’s
web_search, and produce exactly oneweb_search. Then I’ll review the checklist and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.