-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: preserve user images in native tool call results #9401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When native tool calls are enabled, user images sent with responses were being converted to placeholder text '(image content)' instead of being preserved and sent to the LLM. This fix: - Preserves image blocks in tool_result content as arrays when images are present - Only converts to string when no images exist (for cleaner representation) - Maintains compatibility with Anthropic API's tool_result format Also adds comprehensive test coverage for image handling in both native and XML protocols.
Review completed. No issues found - the implementation correctly preserves images in native protocol tool results while maintaining backward compatibility. Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Images should be added as separate blocks after tool_result, not inside the tool_result content itself. This follows the Anthropic API specification where tool_result content must be a string, and images are separate content blocks in the user message. Updated tests to verify images are correctly added as separate blocks in the user message content.
Review completed. No issues found - the implementation correctly preserves images in native protocol tool results while maintaining backward compatibility. Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Problem
When native tool calls are enabled, user images sent with responses were being converted to placeholder text
(image content)instead of being preserved and sent to the LLM. This caused the model to lose important visual context that users were providing.Solution
Modified the
pushToolResultfunction inpresentAssistantMessage.tsto:Changes
Modified:
src/core/assistant-message/presentAssistantMessage.tspushToolResultfunction to detect and preserve image blocksArray<TextBlockParam | ImageBlockParam>when presentAdded:
src/core/assistant-message/__tests__/presentAssistantMessage-images.spec.tsTesting
All tests pass, including:
Impact
Important
Fixes image preservation in native tool call results by updating
pushToolResultinpresentAssistantMessage.tsto handle image blocks correctly.pushToolResultinpresentAssistantMessage.tsnow preserves image blocks in tool results for native protocol.presentAssistantMessage-images.spec.tswith 4 test cases for image handling in native and XML protocols.This description was created by
for b5dc163. You can customize this summary. It will automatically update as commits are pushed.