Skip to content

fix(anthropic): support code execution tool results#2158

Merged
gold-silver-copper merged 2 commits into
mainfrom
test/anthropic-code-execution-tool-result-2154
Jul 16, 2026
Merged

fix(anthropic): support code execution tool results#2158
gold-silver-copper merged 2 commits into
mainfrom
test/anthropic-code-execution-tool-result-2154

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add explicit support for Anthropic code_execution_tool_result content blocks
  • preserve normal and encrypted code-execution results through non-streaming, streaming, and multi-turn transcript round-trips
  • add focused unit coverage and enable a live-recorded cassette regression for web_search_20260209

Closes #2154.

Root cause

Anthropic's web_search_20260209 tool uses hosted code execution for dynamic filtering. Responses can therefore include top-level code_execution_tool_result blocks containing either code_execution_result or encrypted_code_execution_result payloads.

Rig's tagged Anthropic Content enum did not recognize that top-level variant, causing response deserialization to fail before callers received the completion.

Implementation

  • model code_execution_tool_result explicitly with its tool_use_id and provider-native JSON content
  • preserve the complete block using the existing anthropic_content metadata convention
  • accept preserved blocks when converting Rig messages back to Anthropic requests
  • handle the block consistently in streaming content_block_start events
  • recognize code-execution results when evaluating server-tool transcript boundaries

The implementation deliberately avoids a catch-all unknown-content fallback so unrelated future Anthropic variants still fail visibly instead of being silently discarded.

Regression coverage

The cassette was recorded against Anthropic with web_search_20260209 and contains both normal and encrypted code-execution results. The enabled regression test verifies that the request succeeds and that a code_execution_tool_result block remains available in the normalized response metadata.

Focused unit tests cover:

  • normal code_execution_result deserialization
  • encrypted encrypted_code_execution_result deserialization
  • non-streaming raw metadata preservation and request round-trip
  • streaming block preservation

Verification

  • cargo fmt --check
  • git diff --check
  • cargo test -p rig-core code_execution_tool_result -- --nocapture — 3 passed
  • env -u ANTHROPIC_API_KEY cargo test -p rig --all-features --test anthropic web_search_with_dynamic_filtering_succeeds -- --nocapture --test-threads=1 — passed
  • cargo test -p rig --all-features --test anthropic cassette_safety -- --nocapture --test-threads=1 — 2 passed
  • env -u ANTHROPIC_API_KEY cargo test -p rig --all-features --test anthropic anthropic::cassette -- --nocapture --test-threads=1 — 66 passed
  • cargo clippy --all-targets --all-features -- -D warnings — passed
  • cargo test — passed

All required GitHub checks pass: formatting, WASM check, clippy, tests, documentation, and doctests.

Review

An independent review of the complete diff found no P0/P1 or lower-severity correctness or security issues. Cassette safety checks pass, the fixture contains no credentials, and there are no unresolved review threads.

@gold-silver-copper gold-silver-copper changed the title test: reproduce Anthropic code execution result error fix(anthropic): support code execution tool results Jul 16, 2026
@gold-silver-copper gold-silver-copper marked this pull request as ready for review July 16, 2026 03:55
@gold-silver-copper gold-silver-copper added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit 235e346 Jul 16, 2026
6 checks passed
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.

Anthropic api returns unknown field "code_execution_tool_result" when trying to use server-side "web_search_20260209" tool

1 participant