fix(code_interpreter): preserve binary content in _create_tool_result #371
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