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 start by exploring the repository structure to understand the codebase.
Assistant
Let me look for the Anthropic provider code and web search related code.
Assistant
Let me look at how the tools from this config flow and where they get merged with LibreChat's tools.
Assistant
Let me look at how the tools array (from getLLMConfig) is used in the agent/run flow. Let me find where
getLLMConfigis called and how thetoolsarray gets combined with LibreChat tools.Assistant
Now let me understand how the result (with
toolsandllmConfig) is consumed. Let me look at whereresult.toolsis used.Assistant
Let me look at where the agent initializes and binds tools. Let me find where
result.tools(from initialize) gets used in the run.Assistant
Let me look at the existing tests and the tools.spec.ts for the Anthropic web search behavior.
Assistant
Let me look at the Anthropic llm.spec.ts tests for the web search tools.
Assistant
Let me look at the broader context in initialize.ts to understand structuredTools and options.tools.
Assistant
Now I understand.
structuredToolsare the LibreChat tools (loaded via loadTools based on agent.tools names), andoptions.toolsare the provider-native tools (fromgetLLMConfig'sresult.tools).When both LibreChat
web_searchand Anthropic nativeweb_searchare enabled:- structuredTools includes the LibreChat
web_searchtool (StructuredTool with name 'web_search') - options.tools includes
{ type: 'web_search_20250305', name: 'web_search' } - They get concatenated → duplicate
web_searchname → Anthropic rejects.
The fix: prefer LibreChat's definition. So when LibreChat
web_searchis present in structuredTools, remove the native web_search tool from options.tools (for Anthropic).Now, where to best implement this? Let me think about the cleanest, most general approach that:
- Only affects Anthropic native web_search.
- Prefers LibreChat's definition.
- Doesn't affect unrelated tools or other providers.
I think the best place is at the combination point in initialize.ts, where we filter out the native web_search from options.tools if LibreChat's web_search is in structuredTools, but only for Anthropic.
Actually wait — let me reconsider. The native web_search tool is Anthropic-specific (only Anthropic's getLLMConfig adds it). So filtering the native web_search from options.tools whenever LibreChat's web_search is present would only affect Anthropic anyway. But to be safe and explicit, I'll scope it to Anthropic.
Let me check the Tools enum to get the exact name.
- structuredTools includes the LibreChat
Assistant
Let me look at the full context around the tool combination and the imports in initialize.ts.
Assistant
Let me view the combination logic in full context.
Assistant
Let me look at the existing tests for the initialize combination logic.
Assistant
Let me look at the test around line 1334 (OpenAI concat branch) and the createMocks helper.
Assistant
Let me look at the test around line 745-970 to understand how tools get loaded and checked.
Assistant
Let me look at the end of initializeAgent to see what's returned.
Assistant
Let me check how the web_search capability maps to agent.tools and model_parameters.web_search.
Assistant
Let me look at run.ts to understand how initializeAgent is called and the tool modes.
Assistant
So
loadTools: deps.loadAgentTools. Let me check loadAgentTools to understand whether it returns structuredTools or toolDefinitions.Assistant
Let me look at
loadToolDefinitionsWrapper(the definitionsOnly path).Assistant
Let me understand how
web_search: trueflows into model_parameters for Anthropic. Let me search.Assistant
Let me search where
web_searchgets injected into model_parameters.Assistant
Let me look at the
app/checks.tswhich referenced web_search.Assistant
Let me check how
toolsandtoolDefinitionsare consumed downstream in run.ts / the graph.Assistant
Let me find where
toolsandtoolDefinitionsget merged into the final tool list sent to the LLM.Assistant
Let me look at where
graphToolsis set and how the native web_search binds.Assistant
Let me see where AgentContext.tools is set from the run config.
Assistant
Let me check OpenAI and Google configs to see if they emit native
web_searchnamed tools.Assistant
So:
- Google/Vertex native web search uses
{ googleSearch: {} }(no name 'web_search'). - OpenAI config delegates to
getAnthropicLLMConfigwhen provider is Anthropic (for OpenAI-compatible Anthropic endpoints), so it would also produce the native{ type: 'web_search_20250305', name: 'web_search' }.
So the native web_search with name 'web_search' is only from Anthropic's getLLMConfig (directly or via OpenAI config delegation).
Now let me confirm: for the OpenAI config delegating to Anthropic, what provider does the agent have? Let me look at openai/config.ts to see when it delegates.
- Google/Vertex native web search uses
Assistant
I now understand both modes. Let me look at the region between the loadToolsResult destructure and the combination block to find the best insertion point.
Assistant
I now have a clear plan. Let me check if there's an exported constant for the Anthropic native web search tool type.
Assistant
Let me check the pure OpenAI LLM config to confirm it doesn't emit a
web_searchnamed tool.Assistant
Interesting — OpenAI's native web_search is
{ type: 'web_search' }(noname), while Anthropic's is{ type: 'web_search_20250305', name: 'web_search' }. Let me check theInitializeResultBasetype fortools.Assistant
Let me check how structuredTools/toolDefinitions names are accessed in initialize.ts already.
Assistant
Let me look at the area around the module-level helpers to place a new helper.
Assistant
Let me check how tests are run in the api package.
Assistant
Let me run the existing initialize test to confirm the test infrastructure works.
Assistant
The data-provider module isn't resolving. Let me check the jest config and whether data-provider is built.
Assistant
The data-provider dist doesn't exist. Let me build the required packages.
Assistant
The existing tests pass. Now let me write a temporary reproduction test to confirm the bug.
Assistant
Let me look at the full GOOGLE_TOOL_CONFLICT test and the test file's tail to mimic structure for my reproduction.
Assistant
Now let me create a temporary reproduction test file.
Assistant
I've confirmed the bug in both modes. Now let me check the
GenericTooltype to write the helper correctly.Assistant
I've confirmed the bug in both modes. Now let me implement the fix. First, let me add a helper function after
appendAdditionalInstructions.Assistant
Now let me add the helper function after
appendAdditionalInstructions:Assistant
There's an extra
}at line 67. Let me fix it.Assistant
There's a duplicate
/**at lines 68-69. Let me fix it.Assistant
Let me add a blank line between the function and the next comment block.
Assistant
There's a duplicate
*/at line 109. Let me fix it.Assistant
The helper is now properly defined. Now let me find the combination block to add the call.
Assistant
Now let me add the call to
preferLibreChatWebSearchright before thehasAgentToolsline.Assistant
There's a duplicate
const hasAgentToolsat line 876. Let me fix it.Assistant
The code looks correct now. Let me run the reproduction test to confirm the fix works.
Assistant
The fix works. Let me extend the reproduction to test edge cases: native-only preserved, unrelated tools preserved, other providers unaffected.
Assistant
All edge cases pass. Now let me run the existing initialize test suite to ensure nothing broke.
Assistant
All existing tests pass. Let me run the broader agents test suite and the Anthropic llm tests to be safe.
Assistant
All tests pass. Now let me verify TypeScript compiles correctly with a type check.
Assistant
These are pre-existing type errors unrelated to my change. Let me confirm none are in
initialize.ts.Assistant
No errors in
initialize.ts. Let me verify these 21 errors are pre-existing by stashing my changes and re-running.Assistant
Let me check what changed in package.json and package-lock.json (they might be unintended).
Assistant
The
package.json/package-lock.jsonchanges are unintended side effects from the build. Let me revert them to keep the change focused.Assistant
Now my change is focused. Let me review the final diff.
Assistant
Let me check whether there's a parallel legacy (non-agent) flow that also combines LibreChat tools with the Anthropic native web_search tool.
Assistant
Let me look at the legacy Anthropic client flow to see if it also combines LibreChat tools with native web_search.
Assistant
Let me check where
initializeAnthropic/ the legacy Anthropic client consumes thetoolsfrom the result.Assistant
Let me check the legacy non-agent flow to see if
getOptions/tools is combined with LibreChat tools there too.Assistant
Let me check how the legacy (non-agent) flow consumes
getOptionsand combines tools.Assistant
Let me run the OpenAI config tests too, since OpenAI config delegates to Anthropic's getLLMConfig.
Assistant
Let me check the api/server
initialize.jsto see if it's a parallel implementation that also combines tools.Assistant
The api/server
initialize.jsimportsinitializeAgentfrom@librechat/api. Let me check how@librechat/apiresolves (dist vs src) so the JS side picks up my change.Assistant
@librechat/api's main isdist/index.js. Let me build the api package so the JS flow reflects the change, then revert any unintended package.json/lock changes.Assistant
The build succeeded. Let me verify the dist contains my change and revert any unintended package.json/lock changes.
Assistant
The dist contains my change and is gitignored. Let me run the api/server JS tests that exercise the agent/tool flow to ensure the build works end-to-end.
Assistant
Both api/server JS test suites pass. Let me run the broader agents controller tests to be thorough.
Assistant
All tests pass. Now let me remove the temporary reproduction test file.
Assistant
Only
initialize.tsis modified (dist is gitignored). Let me do a final review of the complete diff.Assistant
The change is clean and focused. Let me run the initialize test suite once more to confirm everything is green after removing the repro file.
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 →