fix(code_interpreter): preserve binary content in _create_tool_result#371
Open
strands-agent wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(code_interpreter): preserve binary content in _create_tool_result#371strands-agent wants to merge 1 commit intostrands-agents:mainfrom
strands-agent wants to merge 1 commit intostrands-agents:mainfrom
Conversation
When reading binary files (e.g., PNG images) via readFiles, the content may already be a properly structured list. Previously, _create_tool_result would wrap all content in str(), destroying binary data by converting bytes like b'\x89PNG...' to a string representation "b'\x89PNG...'". This fix preserves content structure when it's already a list, and only wraps non-list content in text format for backward compatibility. Fixes: strands-agents#370
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.
Description
Fixes an issue where
_create_tool_resultinAgentCoreCodeInterpreterstringifies binary content, breakingreadFilesfor binary files like PNG images.Problem: When reading binary files via
readFiles, the content may already be a properly structured list. The previous implementation wrapped all content instr(), converting bytes likeb'\x89PNG...'to a string representation"b'\\x89PNG...'".Solution: Preserve content structure when it's already a list, and only wrap non-list content in text format for backward compatibility.
Related Issues
Fixes #370
Documentation PR
No documentation changes required.
Type of Change
Testing
test_create_tool_result_preserves_list_content- Verifies binary content preservationtest_create_tool_result_wraps_string_content- Verifies backward compatibility for string contenttest_create_tool_result_preserves_list_on_error- Verifies list preservation on errorsruff formatandruff checkChecklist