fix(codex): preserve images in tool results#59
Merged
Conversation
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.
Owner
|
Thank you |
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
Preserve image blocks returned by Claude Code tools when translating Anthropic requests to the Codex Responses API.
Previously, images nested inside
tool_resultwere replaced with textual[image omitted: ...]placeholders. This prevented Codex models from seeing images returned by tools such asRead.The Responses API supports structured
function_call_output.outputcontent containing bothinput_textandinput_imageitems:view_imagetestChanges
function_call_output.outputas either:input_textandinput_imagecontent items when images are present.data:URLs.Text-only tool results retain their existing wire representation.
Verification
cargo checkcargo test --lib: 497 passedrustfmt --checkgit diff --checkReadtool on a WebP screenshot through an isolated proxy instance. The model correctly extracted the exact model identifier visible in the image.