Skip to content

Conversation

@strands-agent
Copy link
Contributor

Description

Fixes an issue where _create_tool_result in AgentCoreCodeInterpreter stringifies binary content, breaking readFiles for 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 in str(), converting bytes like b'\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

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Added 3 new unit tests:
    • test_create_tool_result_preserves_list_content - Verifies binary content preservation
    • test_create_tool_result_wraps_string_content - Verifies backward compatibility for string content
    • test_create_tool_result_preserves_list_on_error - Verifies list preservation on errors
  • All existing tests pass
  • I ran ruff format and ruff check

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective
  • My changes generate no new warnings

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AgentCoreCodeInterpreter's _create_tool_result stringifies binary content, breaking readFiles for binary files

1 participant