Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Anthropic rejects duplicate websearch tool names When LibreChat web…

  1. 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_search tool 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. GLM Assistant

    I'll start by exploring the repository structure to understand the codebase.

  3. GLM Assistant

    Let me look for the Anthropic provider code and web search related code.

  4. GLM Assistant

    Let me look at how the tools from this config flow and where they get merged with LibreChat's tools.

  5. GLM Assistant

    Let me look at how the tools array (from getLLMConfig) is used in the agent/run flow. Let me find where getLLMConfig is called and how the tools array gets combined with LibreChat tools.

  6. GLM Assistant

    Now let me understand how the result (with tools and llmConfig) is consumed. Let me look at where result.tools is used.

  7. GLM 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.

  8. GLM Assistant

    Let me look at the existing tests and the tools.spec.ts for the Anthropic web search behavior.

  9. GLM Assistant

    Let me look at the Anthropic llm.spec.ts tests for the web search tools.

  10. GLM Assistant

    Let me look at the broader context in initialize.ts to understand structuredTools and options.tools.

  11. GLM Assistant

    Now I understand. structuredTools are the LibreChat tools (loaded via loadTools based on agent.tools names), and options.tools are the provider-native tools (from getLLMConfig's result.tools).

    When both LibreChat web_search and Anthropic native web_search are enabled:

    • structuredTools includes the LibreChat web_search tool (StructuredTool with name 'web_search')
    • options.tools includes { type: 'web_search_20250305', name: 'web_search' }
    • They get concatenated → duplicate web_search name → Anthropic rejects.

    The fix: prefer LibreChat's definition. So when LibreChat web_search is 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:

    1. Only affects Anthropic native web_search.
    2. Prefers LibreChat's definition.
    3. 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.

  12. GLM Assistant

    Let me look at the full context around the tool combination and the imports in initialize.ts.

  13. GLM Assistant

    Let me view the combination logic in full context.

  14. GLM Assistant

    Let me look at the existing tests for the initialize combination logic.

  15. GLM Assistant

    Let me look at the test around line 1334 (OpenAI concat branch) and the createMocks helper.

  16. GLM Assistant

    Let me look at the test around line 745-970 to understand how tools get loaded and checked.

  17. GLM Assistant

    Let me look at the end of initializeAgent to see what's returned.

  18. GLM Assistant

    Let me check how the web_search capability maps to agent.tools and model_parameters.web_search.

  19. GLM Assistant

    Let me look at run.ts to understand how initializeAgent is called and the tool modes.

  20. GLM Assistant

    So loadTools: deps.loadAgentTools. Let me check loadAgentTools to understand whether it returns structuredTools or toolDefinitions.

  21. GLM Assistant

    Let me look at loadToolDefinitionsWrapper (the definitionsOnly path).

  22. GLM Assistant

    Let me understand how web_search: true flows into model_parameters for Anthropic. Let me search.

  23. GLM Assistant

    Let me search where web_search gets injected into model_parameters.

  24. GLM Assistant

    Let me look at the app/checks.ts which referenced web_search.

  25. GLM Assistant

    Let me check how tools and toolDefinitions are consumed downstream in run.ts / the graph.

  26. GLM Assistant

    Let me find where tools and toolDefinitions get merged into the final tool list sent to the LLM.

  27. GLM Assistant

    Let me look at where graphTools is set and how the native web_search binds.

  28. GLM Assistant

    Let me see where AgentContext.tools is set from the run config.

  29. GLM Assistant

    Let me check OpenAI and Google configs to see if they emit native web_search named tools.

  30. GLM Assistant

    So:

    • Google/Vertex native web search uses { googleSearch: {} } (no name 'web_search').
    • OpenAI config delegates to getAnthropicLLMConfig when 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.

  31. GLM 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.

  32. GLM Assistant

    I now have a clear plan. Let me check if there's an exported constant for the Anthropic native web search tool type.

  33. GLM Assistant

    Let me check the pure OpenAI LLM config to confirm it doesn't emit a web_search named tool.

  34. GLM Assistant

    Interesting — OpenAI's native web_search is { type: 'web_search' } (no name), while Anthropic's is { type: 'web_search_20250305', name: 'web_search' }. Let me check the InitializeResultBase type for tools.

  35. GLM Assistant

    Let me check how structuredTools/toolDefinitions names are accessed in initialize.ts already.

  36. GLM Assistant

    Let me look at the area around the module-level helpers to place a new helper.

  37. GLM Assistant

    Let me check how tests are run in the api package.

  38. GLM Assistant

    Let me run the existing initialize test to confirm the test infrastructure works.

  39. GLM Assistant

    The data-provider module isn't resolving. Let me check the jest config and whether data-provider is built.

  40. GLM Assistant

    The data-provider dist doesn't exist. Let me build the required packages.

  41. GLM Assistant

    The existing tests pass. Now let me write a temporary reproduction test to confirm the bug.

  42. GLM Assistant

    Let me look at the full GOOGLE_TOOL_CONFLICT test and the test file's tail to mimic structure for my reproduction.

  43. GLM Assistant

    Now let me create a temporary reproduction test file.

  44. GLM Assistant

    I've confirmed the bug in both modes. Now let me check the GenericTool type to write the helper correctly.

  45. GLM Assistant

    I've confirmed the bug in both modes. Now let me implement the fix. First, let me add a helper function after appendAdditionalInstructions.

  46. GLM Assistant

    Now let me add the helper function after appendAdditionalInstructions:

  47. GLM Assistant

    There's an extra } at line 67. Let me fix it.

  48. GLM Assistant

    There's a duplicate /** at lines 68-69. Let me fix it.

  49. GLM Assistant

    Let me add a blank line between the function and the next comment block.

  50. GLM Assistant

    There's a duplicate */ at line 109. Let me fix it.

  51. GLM Assistant

    The helper is now properly defined. Now let me find the combination block to add the call.

  52. GLM Assistant

    Now let me add the call to preferLibreChatWebSearch right before the hasAgentTools line.

  53. GLM Assistant

    There's a duplicate const hasAgentTools at line 876. Let me fix it.

  54. GLM Assistant

    The code looks correct now. Let me run the reproduction test to confirm the fix works.

  55. GLM Assistant

    The fix works. Let me extend the reproduction to test edge cases: native-only preserved, unrelated tools preserved, other providers unaffected.

  56. GLM Assistant

    All edge cases pass. Now let me run the existing initialize test suite to ensure nothing broke.

  57. GLM Assistant

    All existing tests pass. Let me run the broader agents test suite and the Anthropic llm tests to be safe.

  58. GLM Assistant

    All tests pass. Now let me verify TypeScript compiles correctly with a type check.

  59. GLM Assistant

    These are pre-existing type errors unrelated to my change. Let me confirm none are in initialize.ts.

  60. GLM Assistant

    No errors in initialize.ts. Let me verify these 21 errors are pre-existing by stashing my changes and re-running.

  61. GLM Assistant

    Let me check what changed in package.json and package-lock.json (they might be unintended).

  62. GLM Assistant

    The package.json/package-lock.json changes are unintended side effects from the build. Let me revert them to keep the change focused.

  63. GLM Assistant

    Now my change is focused. Let me review the final diff.

  64. GLM 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.

  65. GLM Assistant

    Let me look at the legacy Anthropic client flow to see if it also combines LibreChat tools with native web_search.

  66. GLM Assistant

    Let me check where initializeAnthropic / the legacy Anthropic client consumes the tools from the result.

  67. GLM Assistant

    Let me check the legacy non-agent flow to see if getOptions/tools is combined with LibreChat tools there too.

  68. GLM Assistant

    Let me check how the legacy (non-agent) flow consumes getOptions and combines tools.

  69. GLM Assistant

    Let me run the OpenAI config tests too, since OpenAI config delegates to Anthropic's getLLMConfig.

  70. GLM Assistant

    Let me check the api/server initialize.js to see if it's a parallel implementation that also combines tools.

  71. GLM Assistant

    The api/server initialize.js imports initializeAgent from @librechat/api. Let me check how @librechat/api resolves (dist vs src) so the JS side picks up my change.

  72. GLM Assistant

    @librechat/api's main is dist/index.js. Let me build the api package so the JS flow reflects the change, then revert any unintended package.json/lock changes.

  73. GLM Assistant

    The build succeeded. Let me verify the dist contains my change and revert any unintended package.json/lock changes.

  74. GLM 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.

  75. GLM Assistant

    Both api/server JS test suites pass. Let me run the broader agents controller tests to be thorough.

  76. GLM Assistant

    All tests pass. Now let me remove the temporary reproduction test file.

  77. GLM Assistant

    Only initialize.ts is modified (dist is gitignored). Let me do a final review of the complete diff.

  78. GLM 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.