Skip to content

fix(openai-chat): deliver tool-result images to vision models - #912

Open
DevMello wants to merge 3 commits into
lidge-jun:devfrom
DevMello:fix/tool-result-images-openai-chat
Open

fix(openai-chat): deliver tool-result images to vision models#912
DevMello wants to merge 3 commits into
lidge-jun:devfrom
DevMello:fix/tool-result-images-openai-chat

Conversation

@DevMello

@DevMello DevMello commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Fixes #888. Images in a tool result were flattened to the literal string "[image]", so vision models like kimi-k3 never saw the actual image and made up a description (Claude Code sends Read and screenshot output this way).

role:"tool" messages can only carry text on chat providers, so the adapter now re-sends the image parts in a user vision message once the tool round closes, the same approach the Google and Kiro adapters already use. Models in noVisionModels still go through the vision sidecar.

Also added a line to the adapter docs. The Japanese, Korean, Russian, and Chinese versions were done with AI translation, so a quick check from native speakers would help.

Verification

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Notes

Rebased onto current dev (was accidentally based on the dev/main release-promotion point for v2.10.0). Source commit before the rebase: a719509.

Summary by CodeRabbit

  • New Features

    • Tool-result images are now preserved when using the OpenAI Chat adapter.
    • Images are sent in a follow-up user vision message, while the original tool message retains an [image] marker.
    • Supports multiple tool calls, interrupted rounds, and orphaned tool results.
  • Documentation

    • Updated adapter documentation in English, Japanese, Korean, Russian, and Simplified Chinese to describe image handling.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

PR quality gates passed

This pull request now targets dev with acceptable ancestry and description.

The title was left unchanged. The pull request has been marked ready for review again.

@github-actions
github-actions Bot marked this pull request as draft August 2, 2026 22:57
@github-actions github-actions Bot added the bug Something isn't working label Aug 2, 2026
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 78619e20-7ec9-41d1-8bba-b4ab1e34299f

📥 Commits

Reviewing files that changed from the base of the PR and between 9c8a0c5 and d0a525d.

📒 Files selected for processing (4)
  • docs-site/src/content/docs/ru/reference/adapters.md
  • docs-site/src/content/docs/zh-cn/reference/adapters.md
  • src/adapters/openai-chat.ts
  • tests/openai-chat-tool-result-images.test.ts
 _____________________
< Git gud or git out. >
 ---------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
📝 Walkthrough

Walkthrough

The OpenAI Chat adapter forwards tool-result images in a follow-up user vision message after the tool round. Tool messages retain text and an [image] marker. Tests and Japanese, Korean, and English documentation cover the behavior.

Changes

Tool-result image forwarding

Layer / File(s) Summary
Image conversion and round state
src/adapters/openai-chat.ts
Tool-result images become image_url parts with optional detail metadata. The adapter accumulates them during an active tool round.
Tool-round image flushing
src/adapters/openai-chat.ts
Collected images emit as one user vision message after completed, interrupted, or orphan tool results. Deferred barrier messages remain ordered after the image message.
Behavior validation and adapter documentation
tests/openai-chat-tool-result-images.test.ts, docs-site/src/content/docs/reference/adapters.md, docs-site/src/content/docs/ja/reference/adapters.md, docs-site/src/content/docs/ko/reference/adapters.md
Tests cover normal, multi-call, orphan, interrupted, and image-free results. Documentation describes the follow-up vision message and retained marker.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ToolResult
  participant OpenAIChatAdapter
  participant OpenAIChatRequest
  ToolResult->>OpenAIChatAdapter: Provide text and image content
  OpenAIChatAdapter->>OpenAIChatRequest: Emit text-only tool message with [image]
  OpenAIChatAdapter->>OpenAIChatRequest: Emit follow-up user vision message with image_url parts
Loading

Possibly related PRs

Suggested reviewers: lidge-jun, ingwannu, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The adapter forwards tool-result images to vision-capable models, with tests covering relevant tool-round cases described in [#888].
Out of Scope Changes check ✅ Passed The implementation, tests, and localized documentation directly support image forwarding for the OpenAI Chat adapter and remain within [#888].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: forwarding tool-result images to vision models in the OpenAI Chat adapter.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs-site/src/content/docs/reference/adapters.md`:
- Around line 34-36: Add the tool-result image behavior to the corresponding
openai-chat sections in both translated adapter pages: document that the
text-only role:"tool" message retains a short [image] marker, while the actual
images are delivered as image_url parts in one follow-up user vision message
after the tool round closes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 839db9c6-9a30-4061-84de-2b79886cba9c

📥 Commits

Reviewing files that changed from the base of the PR and between 4a0d038 and a719509.

📒 Files selected for processing (5)
  • docs-site/src/content/docs/ja/reference/adapters.md
  • docs-site/src/content/docs/ko/reference/adapters.md
  • docs-site/src/content/docs/reference/adapters.md
  • src/adapters/openai-chat.ts
  • tests/openai-chat-tool-result-images.test.ts

Comment thread docs-site/src/content/docs/reference/adapters.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a719509eaf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const parts: unknown[] = [];
for (const p of content) {
if (p.type !== "image") continue;
parts.push({ type: "image_url", image_url: { url: p.imageUrl, ...(p.detail ? { detail: p.detail } : {}) } });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard empty tool-result image URLs

When a tool output contains a malformed input_image with an empty image_url (the tool-output parser currently accepts any string here, including the image_url: "", file_id: "..." shape that user input omits), this new carrier forwards {"image_url":{"url":""}} to the chat provider. Vision-capable OpenAI-compatible endpoints reject malformed image_url parts, so a bad tool image that previously degraded to the [image] marker can now fail the whole request; skip non-usable URLs before adding carrier parts.

AGENTS.md reference: src/AGENTS.md:L17-L19

Useful? React with 👍 / 👎.

Images in a tool_result were flattened to a literal "[image]" marker,
so vision-capable routed models (kimi-code, DeepSeek, ...) described
images they never saw. role:"tool" content is text-only on chat
providers, so images now ride in a follow-up user vision message
released once the tool round closes, mirroring the Google and Kiro
adapters. Models in noVisionModels still use the vision sidecar.

Fixes lidge-jun#888
@DevMello
DevMello force-pushed the fix/tool-result-images-openai-chat branch from a719509 to 9c8a0c5 Compare August 2, 2026 23:04
@github-actions
github-actions Bot marked this pull request as ready for review August 2, 2026 23:04
The tool-output parser accepts any string for image_url, including
the empty file_id shape, and a {"url":""} carrier part would fail
the whole request where the "[image]" marker degrades safely.
The first commit only updated the en, ja, and ko adapter pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant