fix(bedrock): preserve image content in tool results for Converse API#2658
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughConvertBifrostMessagesToBedrockMessages now handles image content blocks in structured tool-call outputs: if a block is type Image and has a URL, it attempts conversion via convertImageToBedrockSource and appends a Bedrock image content block when successful; conversion errors silently omit the image block. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Confidence Score: 5/5Safe to merge — the fix is correct and well-tested; one dead-code line is cosmetic and does not affect behavior. All remaining findings are P2. The only issue is a No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "fix(bedrock): preserve image content in ..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@core/providers/bedrock/responses.go`:
- Around line 2568-2574: The code is silently dropping image tool-result blocks
when convertImageToBedrockSource returns an error; update the block handling
around ResponsesInputMessageContentBlockTypeImage so that if
convertImageToBedrockSource(block.ResponsesInputMessageContentBlockImage.ImageURL)
returns an error you do not skip it silently: either log or propagate the error
and append an explicit fallback BedrockContentBlock (e.g., a text/error block
indicating the image URL is unsupported or the conversion failed) instead of
ignoring it; modify the branch that currently does resultContent =
append(resultContent, BedrockContentBlock{Image: imageSource}) to handle err !=
nil by calling the project logger or returning the error and/or appending a
fallback BedrockContentBlock so the failure is surfaced.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a5d40b00-36dd-4626-89c7-46afda125a92
📒 Files selected for processing (1)
core/providers/bedrock/responses.go
a7aa034 to
63f89e1
Compare
When converting Anthropic Messages API tool results to Bedrock Converse
API format, image content blocks in function_call_output were silently
dropped. The existing code only processed text blocks:
for _, block := range output.ResponsesFunctionToolCallOutputBlocks {
if block.Text != nil {
resultContent = append(resultContent, ...)
}
}
This caused tools that return image-only results (e.g. screenshot tools
in computer-use agents) to produce empty tool results. The model would
receive no visual feedback from screenshots, making it unable to
determine what is on screen and causing it to loop endlessly retaking
screenshots.
The fix adds an else-if branch that converts input_image blocks to
BedrockContentBlock with Image data, using the existing
convertImageToBedrockSource utility that already handles image
conversion for regular message content blocks.
Note: convertBifrostResponsesMessageContentBlocksToBedrockContentBlocks
already handles images correctly for regular messages — this gap only
affected the function_call_output (tool result) code path.
Made-with: Cursor
63f89e1 to
aa34874
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@core/providers/bedrock/bedrock_test.go`:
- Around line 3748-3775: The test RemoteURLImageGracefullyDropped currently
asserts that toolResult.Content is empty which reintroduces an empty tool-result
shape; update the test to instead expect a non-empty fallback block or an
explicit conversion error from ConvertBifrostMessagesToBedrockMessages (e.g.,
assert that messages[0].Content[0].ToolResult contains a fallback Content block
or that the function returned an error describing unsupported remote-image URLs)
so the model receives an explicit, usable tool output rather than an empty
result.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 99e02d2d-c399-4afd-b1df-8f8776cc2f4d
📒 Files selected for processing (2)
core/providers/bedrock/bedrock_test.gocore/providers/bedrock/responses.go
Summary
When tool results (e.g. from screenshot/computer-use tools) contain image-only content blocks, the existing Bedrock conversion code in
ConvertBifrostMessagesToBedrockMessagesonly processesblock.Textfields in thefunction_call_outputpath — image blocks are skipped entirely, producing empty tool results.This causes models to receive no visual feedback from screenshot tools, making them unable to determine what is on screen. In practice, the model loops endlessly retaking screenshots because every result comes back empty.
Root Cause
In
core/providers/bedrock/responses.go(~line 2565), the structured output block loop only handles text:Note that
convertBifrostResponsesMessageContentBlocksToBedrockContentBlocks(used for regular message content) already handlesResponsesInputMessageContentBlockTypeImagecorrectly — this gap only affects thefunction_call_output(tool result) code path.Fix
Adds an
else ifbranch that convertsinput_imageblocks toBedrockContentBlock{Image: ...}using the existingconvertImageToBedrockSourceutility:Test plan
ConvertBifrostMessagesToBedrockMessageswith image-containing tool resultsMade with Cursor