Skip to content

fix(codex): preserve images in tool results#59

Merged
raine merged 2 commits into
raine:mainfrom
mulfyx:fix/codex-tool-result-images
Jul 20, 2026
Merged

fix(codex): preserve images in tool results#59
raine merged 2 commits into
raine:mainfrom
mulfyx:fix/codex-tool-result-images

Conversation

@mulfyx

@mulfyx mulfyx commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Preserve image blocks returned by Claude Code tools when translating Anthropic requests to the Codex Responses API.

Previously, images nested inside tool_result were replaced with textual [image omitted: ...] placeholders. This prevented Codex models from seeing images returned by tools such as Read.

The Responses API supports structured function_call_output.output content containing both input_text and input_image items:

Changes

  • Represent function_call_output.output as either:
    • a plain string for text-only results; or
    • structured input_text and input_image content items when images are present.
  • Convert base64 Anthropic image blocks to data: URLs.
  • Pass URL-based image blocks through unchanged.
  • Preserve textual placeholders for malformed or unsupported content blocks.
  • Include tool-result images in request-size diagnostics and token estimates.
  • Update the documented Codex image limitation.

Text-only tool results retain their existing wire representation.

Verification

  • cargo check
  • cargo test --lib: 497 passed
  • rustfmt --check
  • git diff --check
  • End-to-end Claude Code test using the Read tool on a WebP screenshot through an isolated proxy instance. The model correctly extracted the exact model identifier visible in the image.

mulfyx and others added 2 commits July 19, 2026 02:17
Preserving tool-result images exposed mixed-content ordering and validation
failures that could either change model-visible semantics or reject an entire
Codex request.

Translate tool-result blocks into ordered parts, retain the legacy string wire
format for text-only results, and emit structured content only when a supported
base64 image survives validation. Remote URLs and malformed images degrade to
text placeholders at their original positions. Error prefixes and Read guidance
remain ordered around the original content.

Add regression coverage for ordering, media validation, text compatibility,
error placement, and structured token estimates. Document the supported
base64-only tool-result behavior.
@raine
raine merged commit 246c018 into raine:main Jul 20, 2026
1 check passed
@raine

raine commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Thank you

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.

2 participants