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 and then find the relevant Anthropic provider code.

  3. GLM Assistant

    Now let me look at the Anthropic LLM endpoint where web search tools are likely set up.

  4. GLM Assistant

    Now I see the Anthropic LLM config. The web_search tool is added to the tools array. Now I need to understand how this is used downstream and where the duplication could occur with LibreChat's web search. Let me look at the initialize.ts and how tools are used.

  5. GLM Assistant

    Now let me look at the spec file for the Anthropic LLM to understand the existing test patterns.

  6. GLM Assistant

    Now let me understand how the Anthropic endpoint's tools are used. Let me look at the agents code that loads tools and how the Anthropic endpoint config feeds into the agent.

  7. GLM Assistant

    Now let me see how the agent's tools combine with the LLM config tools. Let me look at where the LLM config result is used to bind tools.

  8. GLM Assistant

    Now let me understand where options.tools comes from. Let me look at the caller of initializeAgent and how the LLM config's tools field gets passed.

  9. GLM Assistant

    Let me now find where the LLM config is created and the tools field is bound to the LLM. Let me look at the run.ts and how the agent model is set up.

  10. GLM Assistant

    So the agent.tools (the tool definitions) and clientOptions: llmConfig are passed. The llmConfig is built from agent.model_parameters. Let me look at how the tools from the LLM config (result.tools returned by getLLMConfig) flow into agent.model_parameters. Let me look at the @librechat/agents package where the LLM is constructed and bindTools happens.

  11. GLM Assistant

    Let me look at how the agent tools are loaded and what agent.tools refers to in the initialized agent. Let me check the InitializedAgent type and how the llmConfig tools are passed.

  12. GLM Assistant

    Now I understand the flow. The getLLMConfig (for Anthropic) returns a tools array containing the Anthropic-native web_search tool. These tools get bound to the model. The agent also has LibreChat's web_search tool registered via the tool definitions registry.

    Let me find where options.tools (the LLM config's tools) is consumed and bound.

  13. GLM Assistant

    So initializedAgent.tools is a combination of structuredTools (LibreChat's tools like web_search) + options.tools (the LLM-config's tools like Anthropic's native web_search). For Anthropic, when both are present, they are concatenated: structuredTools.concat(options.tools). This is where the duplicate web_search tool name comes from.

    Let me look at how the LLM is built and tools bound in @librechat/agents to understand the final binding.

  14. GLM Assistant

    So initializeModel calls model.bindTools(tools) with the combined tools array. For Anthropic, both the LibreChat web_search tool (a structured tool with name web_search) and the Anthropic-native web_search tool ({ type: 'web_search_20250305', name: 'web_search' }) would be in the array, causing a duplicate name.

    Let me confirm where the tools passed to initializeModel come from.

  15. GLM Assistant

    So getToolsForBinding returns:

    • If toolDefinitions exist: getEventDrivenToolsForBinding() returns schema tools (from toolDefinitions) + graphTools + instanceTools.
    • Otherwise: filtered instance tools + graphTools.

    The instanceTools come from agent.tools which is the tools returned from initializeAgent — the combination of structuredTools (LibreChat tools) + options.tools (Anthropic native web_search).

    Wait, let me check getEffectiveInstanceTools.

  16. GLM Assistant

    So I now have a clear understanding. The agentContext.tools includes both LibreChat's web_search structured tool and Anthropic's native { type: 'web_search_20250305', name: 'web_search' } tool. When these are bound via bindTools, Anthropic rejects the duplicate name.

    Let me reproduce the issue to understand the error precisely. Let me look at the Anthropic bindTools implementation.

  17. GLM Assistant

    Let me look at how structuredTools is built and what baseToolNames/agentToolNames include.

  18. GLM Assistant

    Let me look at the WebSearchToolDefinition from @librechat/agents.

  19. GLM Assistant

    Let me look at how options.tools (the LLM-config tools) is set up in the initialize tests.

  20. GLM Assistant

    Now let me look at how the existing tests check the concatenation logic for ANTHROPIC.

  21. GLM Assistant

    Let me check the Tools enum and the constants used.

  22. GLM Assistant

    Let me look at the imports and the top portion of initialize.ts.

  23. GLM Assistant

    Let me write a reproduction script to confirm the duplicate web_search issue. First, let me check the test setup.

  24. GLM Assistant

    Let me write a reproduction test to confirm the duplicate web_search issue at the initialize.ts merge point.

  25. GLM Assistant

    Now let me create a temporary reproduction test to confirm the duplicate web_search issue:

  26. GLM Assistant

    The module resolution for librechat-data-provider fails. The existing tests must use a different module resolution. Let me check how the existing test imports work — maybe there's a moduleNameMapper or the package is built. Let me check the node_modules linkage.

  27. GLM Assistant

    The dist directory is empty for librechat-data-provider. Let me check if the existing tests run at all.

  28. GLM Assistant

    The existing tests also fail because the dependent packages need to be built. Let me build the packages.

  29. GLM Assistant

    Let me build the dependent packages so tests can run.

  30. GLM Assistant

    Now let me try running the existing test again.

  31. GLM Assistant

    Now the tests run. Let me run my reproduction test.

  32. GLM Assistant

    I've reproduced the issue. The result tools have two web_search entries: the LibreChat structured tool and the Anthropic-native { type: 'web_search_20250305', name: 'web_search' }.

    Now let me implement the fix in initialize.ts.

  33. GLM Assistant

    Let me check what the loaded LibreChat web_search structured tool actually looks like (its name property).

  34. GLM Assistant

    Let me look at how the web_search structured tool is actually created/loaded so I can confirm it has a name property equal to web_search. Let me look at the agents tools loader in api/server/controllers/agents/openai.js or the loadAgentTools function.

  35. GLM Assistant

    Now I understand the structure. The LibreChat web_search tool has .name === 'web_search'. Let me check the GenericTool type.

  36. GLM Assistant

    Let me check the InitializeResultBase type for the tools field.

  37. GLM Assistant

    Now I'll implement the fix. Let me add a helper function and modify the merge block in initialize.ts.

  38. GLM Assistant

    Now let me add the helper function after appendAdditionalInstructions:

  39. GLM Assistant

    Now let me add the helper function after appendAdditionalInstructions:

  40. GLM Assistant

    Let me use the proper edit command instead. First, let me view the exact lines.

  41. GLM Assistant

    There's a missing blank line between the helper and the next comment. Let me fix that:

  42. GLM Assistant

    Now let me modify the merge block to use the helper. Let me view it:

  43. GLM Assistant

    Let me fix the double blank line:

  44. GLM Assistant

    Now let me run my reproduction test to confirm the fix:

  45. GLM Assistant

    The fix works — now only the LibreChat web_search tool remains. Let me extend my reproduction test to cover edge cases: (1) only Anthropic-native web_search (no LibreChat) keeps native, (2) only LibreChat web search (no native) keeps LibreChat's, (3) unrelated provider tools unaffected, (4) other providers unaffected.

  46. GLM Assistant

    All edge cases pass. Now let me run the existing test suite for initialize.ts to make sure I didn't break anything.

  47. GLM Assistant

    All 34 tests pass. Now let me run the broader agents test suite to ensure nothing else broke.

  48. GLM Assistant

    All agents tests pass (747 passed, 4 skipped). Now let me run the Anthropic-specific tests.

  49. GLM Assistant

    Now let me remove my temporary reproduction test file before submitting.

  50. GLM Assistant

    Let me also check whether there's a legacy/non-agents path that could hit the same duplicate issue.

  51. GLM Assistant

    Let me check the run.ts getOptions usage around line 365 to ensure there's no other merge point.

  52. GLM Assistant

    Let me verify TypeScript compiles correctly. Let me check for a typecheck setup.

  53. GLM Assistant

    These TypeScript errors are pre-existing and unrelated to my change (they're about EModelEndpoint.custom/agents indexing). Let me confirm none are in my edited file:

  54. GLM Assistant

    No TypeScript errors in initialize.ts. Let me verify these pre-existing errors exist on the original code (before my change) by stashing:

  55. GLM Assistant

    I notice package.json and package-lock.json show as modified, which I didn't intend. Let me check what changed there:

  56. GLM Assistant

    The package.json and package-lock.json changes are unrelated to my fix (they're allowScripts from the environment setup). Let me revert them so I only submit my actual fix:

  57. GLM Assistant

    Now only initialize.ts is modified. Let me re-run the tsc check to confirm my change introduces no new errors (same count as baseline):

  58. GLM Assistant

    Same count (33 lines) as the baseline — my change introduces no new TypeScript errors. Now let me view the final diff of my change:

  59. GLM Assistant

    There's a missing blank line between my helper function and the next comment. Let me fix that:

  60. GLM Assistant

    Now let me run the linter (eslint) on the file to ensure formatting compliance.

  61. GLM Assistant

    ESLint passes. Now let me run the full agents test suite once more to confirm everything still passes after the formatting fix:

  62. GLM Assistant

    All 125 tests pass. Let me also run the broader test suite for the agents folder one final time to ensure no regressions:

  63. GLM Assistant

    Let me investigate the event-driven mode case, where LibreChat's web_search might be in toolDefinitions rather than structuredTools. Let me check what loadAgentTools returns.

  64. GLM Assistant

    Let me check buildToolClassification to understand whether toolDefinitions could contain web_search while structuredTools (instance tools) doesn't (deferred loading scenario).

  65. GLM Assistant

    My analysis confirms the fix is sufficient for both regular and event-driven modes, since LibreChat's web_search is always an instance tool in structuredTools (never solely in toolDefinitions, which only holds MCP/PTC/toolSearch defs). Let me run the tools tests to be safe:

  66. GLM Assistant

    All tests pass. Let me do a final review of the complete change and verify the file is in good shape:

  67. GLM Assistant

    Let me verify the Providers.ANTHROPIC value matches what agent.provider would be:

  68. GLM Assistant

    Providers.ANTHROPIC === 'anthropic', which matches agent.provider.

    Let me run the complete relevant test suites one final time to confirm everything passes:

  69. GLM Assistant

    All 911 tests pass. Let me provide the final checklist review.

    Summary

    I resolved the issue where Anthropic rejects duplicate web_search tool names when both LibreChat web search and Anthropic-native web search are enabled.

    Root cause

    In packages/api/src/agents/initialize.ts, when merging tools for the Anthropic provider, the LibreChat web_search structured tool (loaded from the agent's agent.tools) was concatenated with the Anthropic-native web_search server tool ({ type: 'web_search_20250305', name: 'web_search' }, surfaced via the provider LLM config's options.tools). Both share the name web_search, so binding them produces a duplicate name that the Anthropic API rejects.

    Fix

    I added a resolveAnthropicWebSearchConflict helper that, for the Anthropic provider only, drops the Anthropic-native web_search server tool from the provider-supplied LLM-config tools when LibreChat's web_search structured tool is already loaded — preferring LibreChat's definition. The filtered providerTools is then used in place of options.tools throughout the merge logic. For non-Anthropic providers the helper is a pass-through, so unrelated tools and other providers are unaffected.

    Checklist

    • ✅ Reproduced the error: I wrote a temporary test that constructed an Anthropic agent with both web searches enabled and confirmed result.tools contained two tools named web_search (["web_search","web_search"]).
    • ✅ Confirmed the fix resolves the error: The same reproduction then showed only one web_search (LibreChat's), with the native tool dropped. I also verified edge cases: only-native (keeps native), only-LibreChat (keeps LibreChat), unrelated provider tools unaffected, and other providers (OpenAI) unchanged (no regression).
    • ✅ Edge cases handled: Helper guards on provider === ANTHROPIC, requires both providerTools and structuredTools non-empty, and requires a LibreChat web_search instance present. Detection of the native tool uses the type discriminator so LibreChat's structured tool is never accidentally removed. The GOOGLE_TOOL_CONFLICT path still works since providerTools equals options.tools for non-Anthropic.
    • ✅ Existing tests pass: All agents (742), anthropic (91), and tools (78) test suites pass; ESLint clean; no new TypeScript errors introduced (baseline count unchanged). I removed my temporary reproduction test before finishing.

    The change is limited to a single file (packages/api/src/agents/initialize.ts) and introduces no new public interfaces, as specified.

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