Type of issue
issue / bug
Language
Python
Description
Environment
- Package:
libs/deepagents
- Sub-system:
StateBackend (backends/state.py)
Problem Description
When uploading non-UTF-8 binary files (such as .png, .pdf, .zip, or .wav) using StateBackend.upload_files(), a UnicodeDecodeError is correctly caught and the binary payload is base64-encoded. However, the resulting file metadata is still stored with encoding="utf-8" because create_file_data() / update_file_data() is called without specifying encoding="base64".
As a result, the uploaded file is stored with incorrect encoding metadata.
Later, when download_files() is called, it checks the stored encoding value. Since the metadata incorrectly indicates "utf-8", the backend returns the base64 string encoded as UTF-8 bytes instead of decoding it back into the original binary content. This causes binary files to be corrupted after a round trip through StateBackend.
Steps to Reproduce
from deepagents.backends import StateBackend
files_store = {}
be = StateBackend()
be._read_files = lambda: files_store
be._send_files_update = lambda update: files_store.update(update)
binary_data = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR"
be.upload_files([("/image.png", binary_data)])
downloaded = be.download_files(["/image.png"])[0].content
assert downloaded == binary_data, f"Corrupted: {downloaded}"
Actual Output
AssertionError: Corrupted: b'iVBORw0KGgoAAAANSUhEUg=='
Expected Behavior
When binary data triggers the base64 upload path, the file metadata should be stored with:
This allows download_files() (and any other consumers of the stored file metadata) to correctly decode the base64 payload and return the original binary bytes without corruption.
Additional Notes
From my investigation, the issue appears to occur because the upload path base64-encodes the content but does not update the associated encoding metadata before calling create_file_data() or update_file_data().
I'd be happy to work on this issue and submit a pull request with a fix along with unit test coverage in test_state_backend.py if the maintainers agree this is the intended behavior.
Type of issue
issue / bug
Language
Python
Description
Environment
libs/deepagentsStateBackend(backends/state.py)Problem Description
When uploading non-UTF-8 binary files (such as
.png,.pdf,.zip, or.wav) usingStateBackend.upload_files(), aUnicodeDecodeErroris correctly caught and the binary payload is base64-encoded. However, the resulting file metadata is still stored withencoding="utf-8"becausecreate_file_data()/update_file_data()is called without specifyingencoding="base64".As a result, the uploaded file is stored with incorrect encoding metadata.
Later, when
download_files()is called, it checks the stored encoding value. Since the metadata incorrectly indicates"utf-8", the backend returns the base64 string encoded as UTF-8 bytes instead of decoding it back into the original binary content. This causes binary files to be corrupted after a round trip throughStateBackend.Steps to Reproduce
Actual Output
Expected Behavior
When binary data triggers the base64 upload path, the file metadata should be stored with:
This allows
download_files()(and any other consumers of the stored file metadata) to correctly decode the base64 payload and return the original binary bytes without corruption.Additional Notes
From my investigation, the issue appears to occur because the upload path base64-encodes the content but does not update the associated encoding metadata before calling
create_file_data()orupdate_file_data().I'd be happy to work on this issue and submit a pull request with a fix along with unit test coverage in
test_state_backend.pyif the maintainers agree this is the intended behavior.