Skip to content

🧱 fix: Keep Anthropic Server Tool Result Blocks in the Final Message - #731

Open
roman-redl wants to merge 1 commit into
LibreChat-AI:mainfrom
roman-redl:fix/anthropic-server-tool-result-types
Open

roman-redl wants to merge 1 commit into
LibreChat-AI:mainfrom
roman-redl:fix/anthropic-server-tool-result-types

Conversation

@roman-redl

@roman-redl roman-redl commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keep Anthropic server tool result blocks (code_execution_tool_result, web_fetch_tool_result, bash_code_execution_tool_result, text_editor_code_execution_tool_result, tool_search_tool_result) in the final Anthropic message instead of converting them to text blocks.

Refs #690. Complements #720 and #732 (code execution container). #720 fixes _formatContent / _makeMessageChunkFromAnthropicEvent but not this step (so this is Refs, not Fixes: #690 needs both).

Problem

With Anthropic dynamic filtering (web_search_20260209 / web_search_20260318) the model calls code_execution as a server tool. When the same turn continues after a client (MCP) tool call, the request after next fails:

400 invalid_request_error: `code_execution` tool use with id `srvtoolu_...` was found without a corresponding `code_execution_tool_result` block

It shows up when a turn takes several requests (Anthropic re-sends a missing result once, the request after that fails).

Root cause

After the stream, the graph passes the final message through modifyDeltaProperties -> modifyContent, which turns every block whose type is not in allowedTypesByProvider[provider] into a text block. The Anthropic list had server_tool_use, web_search_tool_result and web_search_result, but none of the other server tool result types, so a code_execution_tool_result never reached the replayed history, regardless of what message_inputs does with it.

Fix

Add the five missing server tool result types to allowedTypesByProvider[Providers.ANTHROPIC] in src/messages/core.ts (grouped with web_search_tool_result in one constant). Other providers are unchanged.

Tests

New src/messages/modifyDeltaProperties.test.ts:

  • a code_execution_tool_result block with encrypted_code_execution_result content survives for Anthropic (content and lc_kwargs.content);
  • every server tool result type survives for Anthropic;
  • unknown block types are still converted to text;
  • the types are not allowed for other providers (OpenAI).

Without the fix 7 of the 10 tests fail. npx jest src/messages: 36 suites, 1108 passed, 1 skipped. Full suite: identical set of 22 failing suites as on main (not related to this change). npx tsc diagnostics and npx eslint on the touched files: no new findings.

Verification

Found and verified live on LibreChat v0.8.9 with web_search_20260318, claude-opus-5-5 and MCP client tools, using the same change applied as a build-time patch to the compiled 4.2.7 dist: 6/6 runs without errors including 6-request turns, plus a 4-turn session with 4 researcher subagents and 70 searches with 0 errors (together with the #720 changes).

modifyContent turns every block whose type is not in the provider's allowed list into a text block. The Anthropic list lacked code_execution_tool_result, web_fetch_tool_result, bash_code_execution_tool_result, text_editor_code_execution_tool_result and tool_search_tool_result, so these results never reached the replayed history and Anthropic rejected the request after next with a missing code_execution_tool_result 400.

Allow those types, and cover modifyDeltaProperties with tests.
roman-redl added a commit to roman-redl/parley that referenced this pull request Nov 22, 2026
…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).
danny-avila pushed a commit that referenced this pull request Nov 23, 2026
…#736)

Retain native results and caller linkage through both stream paths and replay. Scope automatic container reuse to the current user turn.

Design credits: tang-ontheway (#720) and roman-redl (#731, #732; reported #690).

Co-authored-by: Lia <lia@librechat.ai>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant