fix(server): deliver screenshot images to the model on custom providers - #2768
Merged
Dani Akash (DaniAkash) merged 2 commits intoSep 28, 2026
Merged
Conversation
The AI SDK MCP client emits an image tool result as the canonical v7 `file`
content part ({ type: 'file', data: { type: 'data', data }, mediaType }), but
the tool-result media extractor only handled the deprecated image-data and
file-data shapes. For any provider that cannot carry media inside a tool result
(OpenRouter and every other custom provider), the image was stripped to
"[Tool content omitted]" and never re-attached, so the agent could not see
screenshots. Providers that keep media in tool results (Anthropic, OpenAI, and
similar) were unaffected because they skip normalization entirely.
Handle the canonical `file` part when re-attaching tool-result media as a
following user message, and in the compaction helpers that classify, render,
and budget binary content, so a screenshot reaches vision-capable models on
every provider.
Fixes #2722
Contributor
✅ Tests passed: 1370/1373Ran 8 of 16 suites (8 not affected by this change).
|
Contributor
|
Dani Akash (DaniAkash)
deleted the
fix/agent-screenshot-image-transport
branch
September 28, 2026 06:52
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.
Fixes #2722
Summary
The built-in agent could not see
screenshotimages on custom / OpenAI-compatible providers (reproduced on OpenRouter with a vision-capable model). The image arrived on providers that keep media inside tool results, but on every other provider the tool result was replaced with[Tool content omitted]and the picture never reached the model, so the agent could only reason from the accessibility tree.Root cause
For providers that cannot carry media inside a tool result, the agent strips the media out of the tool result and re-attaches it as a following user message (
normalizeMessagesForModel). That extractor only recognized the deprecatedimage-data/file-datacontent-part shapes. The AI SDK MCP client actually emits the current canonical v7 shape:A
filepart fell through to the default case, so nothing was extracted and the image was dropped. The same shape gap in the compaction helpers is why the placeholder read[Tool content omitted]and why a screenshot was invisible to the binary-content budget. Providers that keep media in tool results (Anthropic, OpenAI, Azure, Bedrock, Gemini 3) were unaffected because they skip normalization.Fix
message-normalization.ts: handle the canonicalfilepart when re-attaching tool-result media. Only the inlinedatavariant of the tagged data carries bytes, so aurl/referencevariant is left as-is.compaction/content.ts: recognize thefilepart in the three helpers that classify, render, and budget binary tool-result content, so the placeholder reads[Image]/[File]and images are counted for the compaction budget.No change to the providers that already worked; they continue to keep media inside the tool result.
Tests
Added
message-normalization.test.tscovering the canonicalfileimage re-attachment, a non-imagefile, the still-supported deprecatedimage-datashape, a non-inline (url)file, native-media pass-through, and the no-vision case. Existing compaction suites still pass.