Skip to content

fix(deepagents): store StateBackend binary files as base64 - #1001

Merged
Baihao Wang (byhow) merged 2 commits into
mainfrom
byhow/state-backend-binary-base64
Oct 29, 2026
Merged

Baihao Wang (byhow) merged 2 commits into
mainfrom
byhow/state-backend-binary-base64

Conversation

@byhow

@byhow Baihao Wang (byhow) commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Binary files saved to an agent's StateBackend now survive the thread's next run.

Problem

StateBackend.uploadFiles, and write to a binary path, keep raw Uint8Array bytes in files state. Persistence that goes through plain JSON, as a deployed agent's does, turns those bytes into an object of numeric keys ({"0":137,"1":80,…}), so the next run fails files validation with a ZodError before the model is called. Python's StateBackend stores the same bytes as base64 and never hits this.

Change

  • Binary content is stored as base64 text with encoding: "base64", the shape Python uses. read, readRaw, downloadFiles and edit decode it, so callers still get bytes; ls/glob report the decoded size.
  • FileDataV2 and its Zod schema gain an optional encoding field. Entries already stored as Uint8Array still read.
  • Bytes uploaded at a text path that aren't valid UTF-8 are kept byte-for-byte as application/octet-stream, as in Python, instead of being decoded lossily.

Base64 is also about 3× smaller in a checkpoint than a Uint8Array serialized as a number array.

Kept on purpose

  • JS decides text vs binary by MIME type first (a .png is always binary); Python only by whether the bytes decode as UTF-8.
  • The backend decodes at read time, so read/readRaw/downloadFiles keep returning Uint8Array; Python hands callers the base64 string.

Not changed

StoreBackend.uploadFiles stores a raw Uint8Array the same way; left for a follow-up. A thread already broken by numeric-key objects stays broken.

A JSON checkpointer serializes a Uint8Array as an object of numeric keys,
so a thread with an uploaded image failed `files` schema validation on its
next run. Binary uploads and writes now land in state as base64 text with
`encoding: "base64"`, matching the Python StateBackend, and are decoded back
to bytes on read, readRaw, download, and edit. Existing Uint8Array entries
still read as before.

Uploads at text paths whose bytes are not valid UTF-8 are kept as
application/octet-stream instead of being lossily decoded.
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
deepagentsjs-ui Ready Ready Preview Oct 28, 2026 10:44pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 03038a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
deepagents Patch
deepagents-acp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

npm i https://pkg.pr.new/deepagents-acp@1001

deepagents

npm i https://pkg.pr.new/deepagents@1001

@langchain/sandbox-standard-tests

npm i https://pkg.pr.new/@langchain/sandbox-standard-tests@1001

@langchain/daytona

npm i https://pkg.pr.new/@langchain/daytona@1001

@langchain/deno

npm i https://pkg.pr.new/@langchain/deno@1001

@langchain/modal

npm i https://pkg.pr.new/@langchain/modal@1001

@langchain/node-vfs

npm i https://pkg.pr.new/@langchain/node-vfs@1001

@langchain/quickjs

npm i https://pkg.pr.new/@langchain/quickjs@1001

commit: 03038a7

@robin-agent robin-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in Web

@hntrl Hunter Lovell (hntrl) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LangGraph checkpoints should be able to ser/de UInt8Array, if not i'd think thats a regression

(in other words I think we're solving the wrong problem if something isn't encoding properly)

@byhow
Baihao Wang (byhow) merged commit fcb8249 into main Oct 29, 2026
26 checks passed
@byhow
Baihao Wang (byhow) deleted the byhow/state-backend-binary-base64 branch October 29, 2026 18:09
@github-actions github-actions Bot mentioned this pull request Oct 29, 2026
Baihao Wang (byhow) pushed a commit that referenced this pull request Oct 29, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## deepagents-acp@0.1.38

### Patch Changes

- Updated dependencies
[[`bf83c27`](bf83c27),
[`fcb8249`](fcb8249)]:
  - deepagents@1.16.1
## deepagents@1.16.1

### Patch Changes

- [#980](#980)
[`bf83c27`](bf83c27)
Thanks [@byhow](https://github.com/byhow)! - `FilesystemMiddleware` no
longer counts image blocks toward a tool result's eviction limit, and
keeps them in the message when it evicts the result's text.

- [#1001](#1001)
[`fcb8249`](fcb8249)
Thanks [@byhow](https://github.com/byhow)! - `StateBackend` stores
binary uploads and writes as base64 text with `encoding: "base64"`, so
threads with uploaded images or PDFs keep working after a JSON
checkpointer round trip. Uploads at text paths whose bytes are not valid
UTF-8 are kept byte-for-byte as `application/octet-stream` instead of
being lossily decoded.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — 03038a7c Deployed Oct 28, 2026 by vercel[bot]
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.

2 participants