Repository navigation
🔍 feat: Make the Anthropic Web Search Tool Version Configurable - #18707
Open
roman-redl wants to merge 1 commit into
Open
roman-redl wants to merge 1 commit into
roman-redl wants to merge 1 commit into
Conversation
Add `endpoints.anthropic.webSearchToolVersion` to librechat.yaml, accepting `web_search_20250305` (default), `web_search_20260209` or `web_search_20260318`, and use it as the `type` of the built-in web search tool instead of the hardcoded value.
This was referenced Nov 22, 2026
roman-redl
added a commit
to roman-redl/parley
that referenced
this pull request
Nov 22, 2026
…rch_20260318) LibreChat 0.8.9 hardcodes web_search_20250305. The newer version filters the search results with code execution before they enter the context. On the test stack a search-only question cost $0.21 + $0.15 instead of $0.41 + $0.40 for two turns with the same searches, and a 4-turn research session with subagents $1.90 instead of $2.22 (70 searches instead of 27). patch-websearch.sh swaps the type (LibreChat issue #18222, PR LibreChat-AI/LibreChat#18707).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Anthropic built-in web search tool is always sent as
web_search_20250305, so deployments cannot opt into the newer versions, which filter search results with code execution before they enter the context (web_search_20260209;web_search_20260318adds the optionalresponse_inclusionparameter). Measured directly against the Anthropic API on the same 6-search question withclaude-opus-5-5, the older tool used 224,120 input tokens and the newer one 36,987 to 40,701.This adds an optional
endpoints.anthropic.webSearchToolVersionsetting inlibrechat.yaml. It acceptsweb_search_20250305(the default),web_search_20260209orweb_search_20260318, is validated as an enum in the endpoint schema, and becomes thetypeof the web search tool built ingetLLMConfig. With the setting absent, the request is unchanged.The newer versions also need changes in
@librechat/agents: LibreChat-AI/agents#720 (for LibreChat-AI/agents#690), plus two more found on a live test and described in my comment there (the allowed Anthropic block types inmodifyContent, and sending the code execution container id). Without them, a turn that mixes a search with a client tool call fails with HTTP 400. That is why the default staysweb_search_20250305and why the example config notes the requirement.Closes #18222
Depends on LibreChat-AI/agents#720 and the follow-ups described there (only for opting into the newer versions; the default needs nothing new).
How it works
Agents with an Anthropic provider reach
getLLMConfigthroughinitializeAnthropic, so they pick the setting up without further changes. Provider-tool detection inpackages/api/src/agents/initialize.tsmatches on theweb_searchprefix and tool name, so it also covers the new types.Type of change
Testing
Tested environments/configuration:
@librechat/agentschanges above ported to the 4.2.7 dist: an agent onclaude-opus-5-5with MCP tools and researcher subagents onclaude-sonnet-5-5,web_search_20260209andweb_search_20260318. Turns withcode_execution+web_searchand parallel MCP tool calls complete (6 of 6 runs, including turns of 6 requests), and follow-up turns with more searches work. Old vs new tool version on the same deployment:web_search_20250305web_search_20260318In the long session each search costs about 3.7x less; the agent spends part of the saving on more searches.
endpoints.anthropic.webSearchToolVersion(covered throughinitializeAnthropicwith a mocked app config).Automated tests:
packages/data-provider/src/config.anthropic.spec.ts: setting is optional, the three versions are accepted, other values are rejected.packages/api/src/endpoints/anthropic/llm.spec.ts: the configured version is used (both newer versions), and no tool is added whenweb_searchis off.packages/api/src/endpoints/anthropic/initialize.spec.ts: the default staysweb_search_20250305; the endpoint setting reaches the tool.cd packages/api && npx jest src/endpoints/anthropic(161 passed)cd packages/data-provider && npx jest src/config(all passed)packages/api/src/endpoints/openai/config.anthropic.spec.tshas 12 failing tests in my environment with and without this change (checked on the base commit); I did not investigate them.npx tsc --noEmitinpackages/apiandnpm run typecheckinpackages/data-providerScreenshots / recordings
No user-facing change.
Risk / compatibility
Additive and optional: no migration, and an unset value keeps
web_search_20250305. Not covered: custom endpoints that usedefaultParamsEndpoint: anthropicbuild the tool through the same function but have noendpoints.anthropicsetting to read, so they keep the default. The Vertex AI path still sends theweb-search-2025-03-05beta header; whether Vertex accepts the newer versions was not verified.Checklist
librechat.example.yamlis updated, a librechat.ai docs entry for the new key may follow