Skip to content

fix(deepagents): keep image blocks when evicting tool results - #980

Merged
Baihao Wang (byhow) merged 1 commit into
mainfrom
byhow/deepagents/keep-images-on-tool-eviction
Oct 27, 2026
Merged

Baihao Wang (byhow) merged 1 commit into
mainfrom
byhow/deepagents/keep-images-on-tool-eviction

Conversation

@byhow

Copy link
Copy Markdown
Member

FilesystemMiddleware no longer counts image blocks toward a tool result's eviction limit, and it keeps them in the message when it evicts the result's text.


Bug. A tool returning [{ type: "text", … }, { type: "image", url: "data:image/png;base64,…" }], such as a browser screenshot, was always evicted. Tool results were sized with every non-text block JSON-stringified, and one screenshot's base64 (~200 KB) is well over the default 80k-character limit. The result became the "Tool result too large" notice, the image was dropped, and the model never saw it. createDeepAgent has no eviction setting, so callers can't work around it.

Fix.

  • Image blocks (image, image_url) are skipped when sizing a tool result.
  • When a result is evicted, its image blocks are kept next to the notice, and the file holds only the text.
  • buildEvictedHumanContent is generalized to buildEvictedContent, so human-message eviction and tool-result eviction share one helper. Human-message behavior is unchanged.

Python parity. This matches Python deepagents for image blocks: _extract_text_from_message sizes text only, and _build_evicted_content keeps non-text blocks on eviction. It deliberately keeps #581's eviction of large file/document blocks, which Python doesn't do. Those blocks still count toward the limit and are still evicted.

Test plan

🤖 Generated with Claude Code

Image blocks no longer count toward FilesystemMiddleware's tool-result
eviction limit, and an evicted result keeps them next to the notice.
A screenshot's base64 alone exceeded the default limit, so the model
never saw it. Other non-text blocks still count and are evicted.
@changeset-bot

changeset-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2c62a10

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

@vercel

vercel Bot commented Oct 22, 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 22, 2026 10:10pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

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

deepagents

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

@langchain/sandbox-standard-tests

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

@langchain/daytona

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

@langchain/deno

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

@langchain/modal

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

@langchain/node-vfs

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

@langchain/quickjs

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

commit: 2c62a10

@byhow
Baihao Wang (byhow) marked this pull request as ready for review October 22, 2026 22:12

@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

@byhow
Baihao Wang (byhow) merged commit bf83c27 into main Oct 27, 2026
22 checks passed
@byhow
Baihao Wang (byhow) deleted the byhow/deepagents/keep-images-on-tool-eviction branch October 27, 2026 00:35
@github-actions github-actions Bot mentioned this pull request Oct 27, 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>
Raunak Burrows (burrows99) added a commit to burrows99/deepagentsjs that referenced this pull request Nov 24, 2026
main now keeps image blocks (langchain-ai#980). Audio and video blocks were still
counted toward the eviction limit and dropped from an evicted result;
treat them the same as images.

This branch was successfully deployed

1 active deployment
Preview — 2c62a103 Deployed Oct 22, 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