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
Let me explore the repository structure to understand the codebase.
Assistant
Let me understand the issue better. The issue is about Anthropic rejecting duplicate web_search tool names. When LibreChat web search and Anthropic-native web search are both enabled, two
web_searchtools get exposed and Anthropic rejects the duplicate names. The fix should expose only oneweb_searchtool and prefer LibreChat's definition.Let me look at how Anthropic-native web search is handled and where the tools get assembled.
Assistant
Let me search the agents code for Anthropic native web search. The issue mentions "Anthropic-native web search". Let me look at the agents controllers.
Assistant
Let me look at the broader picture. The Anthropic-native web search is probably a feature where Anthropic API supports
web_searchas a built-in tool. Let me search across the whole repo for where Anthropic built-in tools might be configured.Assistant
Let me look at how the Anthropic-native web search might be exposed. Let me search the whole repo for places that build Anthropic tools or where
web_searchmight be added natively.Assistant
This is the key file. Let me look at the Anthropic llm.ts in detail.
Assistant
Now I understand the structure. The
getLLMConfigbuilds Anthropic-native web_search tools and returns them intools. These native tools get combined with the LibreChat tools somewhere. Let me find wheregetLLMConfigis called and how thetoolsfrom the return is combined with the LibreChat tools (which include the LibreChatweb_searchtool definition).Let me search for where
getLLMConfigis used and how thetoolsfield is used.Assistant
Now I need to find where this
toolsfrom the initialize result is consumed and merged with the LibreChat tools.Assistant
Let me look at where
structuredToolsis set in initialize.ts.Assistant
Let me look at the OpenAI config.ts to understand the broader picture of native tools.
Assistant
Let me check the
Toolsenum to know the exact value ofTools.web_search.Assistant
Let me check the
GenericTooltype and how tool names are accessed.Assistant
Now let me look at existing tests for the initialize.ts to understand the test setup.
Assistant
Let me look at the test around line 1270-1340 which deals with options.tools.
Assistant
Now let me view the exact area to edit in initialize.ts.
Assistant
Let me confirm
Toolsis imported in initialize.ts.Assistant
Now let me implement the fix in the concatenation block.
Assistant
Let me check whether the legacy (non-agents) Anthropic client path also merges native tools, to ensure completeness.
Assistant
Now let me build/check the TypeScript compiles and run the relevant tests.
Assistant
Let me run the initialize tests to make sure nothing breaks.
Assistant
The test needs the data-provider built. Let me check the build status and the module resolution.
Assistant
The
librechat-data-providerresolves tonode_modules/librechat-data-providerwhich is a symlink topackages/data-provider. The package's main entry points todistwhich doesn't exist (no dist). So we need to build the data-provider package. Let me check the data-provider package.json main.Assistant
Let me build the data-provider package so tests can resolve the module.
Assistant
All 34 tests pass. Now let me write a reproduction script to confirm the duplicate
web_searchissue and verify the fix.Assistant
Let me look at what
initializeAgentreturns to write a reproduction test.Assistant
Now let me create a temporary reproduction test to confirm the fix works.
Assistant
The manual spec pattern is ignored by jest config. Let me rename it.
Assistant
Both reproduction tests pass. Now let me verify the fix actually addresses the issue by reverting temporarily to confirm the test would fail without the fix.
Assistant
Let me check the unexpected package.json/package-lock.json changes (likely pre-existing, not mine).
Assistant
These package.json/package-lock.json changes are pre-existing environment artifacts unrelated to my fix. Let me revert them so only my fix is submitted.
Assistant
Now let me delete the reproduction test (per instructions not to add tests) and run the broader related test suites to ensure nothing breaks.
Assistant
All 153 tests pass. Let me verify TypeScript types compile cleanly with tsc.
Assistant
No TypeScript errors related to initialize.ts. Let me double-check the full tsc output didn't have errors that would matter. Let me run it once more and capture the summary.
Assistant
Let me check if
distis gitignored and whether the api package build is needed for the runtime.Assistant
distis gitignored. Let me build the api package to verify my change doesn't break the build.Assistant
Build succeeds. Let me verify the final diff and ensure only my intended change remains.
Assistant
The diff is clean—only the intended change. Let me run a few more related agent test suites to be thorough.
Assistant
All tests pass. Let me do a final review of the complete change in context.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.