Repository navigation
fix(anthropic): preserve server tool results and caller for web_search_20260209 - #720
Conversation
|
Tested this on LibreChat v0.8.9 (
With all three, 6 of 6 runs passed (including turns of 6 requests), plus a 4-turn session with 4 researcher subagents, 70 searches and 20 code execution calls without errors. Old vs new tool version on the same deployment:
The new version ran more searches in the long session (and one more subagent in turn 2): with filtered results each search adds far less to the context, about 3.7x less cost per search, so the agents searched more within the same session and still spent less. The LibreChat side (configurable tool version) is LibreChat-AI/LibreChat#18707. |
…layed With Anthropic web search dynamic filtering (web_search_20260209 and later) the model calls code_execution and the nested web_search calls carry caller. @librechat/agents 4.2.7 dropped code_execution_tool_result (stream parser, replay and modifyContent) and stripped caller, so a later request of the turn failed with 400. patch-agents-servertools.sh ports LibreChat-AI/agents#720 to the compiled code and adds the allowed block types fix (LibreChat-AI/agents#731).
Fixes #690
Root Cause
When using Anthropic's
web_search_20260209dynamic filtering tool, assistant turns containserver_tool_use(code_execution), nestedserver_tool_use(web_search) with acallerfield,web_search_tool_resultwithcaller, andcode_execution_tool_result(whosecontentis acode_execution_resultobject). Previously:_makeMessageChunkFromAnthropicEventinsrc/llm/anthropic/utils/message_outputs.tsonly acceptedtool_use,document,server_tool_use, andweb_search_tool_resultoncontent_block_start, droppingcode_execution_tool_result(and other server tool result types)._formatContentinsrc/llm/anthropic/utils/message_inputs.tsrebuiltserver_tool_useandweb_search_tool_resultblocks without preservingcaller._formatContentrejected anysrvtoolu_tool result whosecontentwas neither an array norweb_search_tool_result_error, droppingcode_execution_tool_resultblocks and causing Anthropic HTTP 400 errors on follow-up turns.Changes
code_execution_tool_result,web_fetch_tool_result,bash_code_execution_tool_result,text_editor_code_execution_tool_result, andtool_search_tool_resultto_makeMessageChunkFromAnthropicEventinsrc/llm/anthropic/utils/message_outputs.ts.caller(when present) on rebuiltserver_tool_useand server tool result blocks insrc/llm/anthropic/utils/message_inputs.ts, and passed through non-web_search_tool_resultAnthropic server tool result blocks cleanly (stripping stream-only properties likeindexandinput).src/llm/anthropic/utils/server-tool-inputs.test.tscovering both streaming chunk creation and multi-turn replay forcode_execution+ nestedweb_searchwithcaller+code_execution_tool_result.Verification
npx jest src/llm/anthropic/utils/server-tool-inputs.test.ts src/llm/anthropic/utils/streaming-tool-input.test.ts src/llm/anthropic/utils/tool-id-normalization.test.ts: 3 suites, 42 passed.