Skip to content

fix(deepagents): keep audio and video blocks out of tool result eviction - #951

Open
Raunak Burrows (burrows99) wants to merge 4 commits into
langchain-ai:mainfrom
burrows99:fix/tool-eviction-keeps-media
Open

Raunak Burrows (burrows99) wants to merge 4 commits into
langchain-ai:mainfrom
burrows99:fix/tool-eviction-keeps-media

Conversation

@burrows99

@burrows99 Raunak Burrows (burrows99) commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #947

Update (merged main): #980 has since landed the image part of this on main (image blocks are kept and not counted). I merged main, took its isImageBlock/buildEvictedContent as is, and this PR now only widens that check to audio and video blocks (isMediaBlock), with two new tests (audio+video kept when text is evicted; an audio block alone does not trigger eviction). Both fail on main and pass here; fs.eviction.test.ts 33 passing, oxlint and oxfmt --check clean. The recordings below are from before #980 and show the image case.

When a tool returns a short caption plus a screenshot (e.g. Playwright MCP's browser_take_screenshot), createFilesystemMiddleware measured the result with stringifyToolContent, which JSON.stringifys the image block. The base64 alone always crossed toolTokenLimitBeforeEvict, so the whole result was evicted to a file and the model only got a text preview, without the image.

Image, image_url, audio and video blocks now don't count toward the threshold, and when a tool result's text is evicted they stay on the replacement message, the same way buildEvictedHumanContent already handles human messages. File and document blocks are still counted and evicted as before, which the existing tests cover.

How I verified it:

  • Two tests in fs.eviction.test.ts (a short caption plus a 200 KB image is not evicted; large text plus an image is evicted with the image kept). Both fail on main and pass with this change.
  • pnpm test:unit in libs/deepagents (1652 passing), oxlint, oxfmt --check.
  • A standalone repro using the issue's exact setup: on main the model receives a plain string preview; with the fix it receives the caption and the image_url block (recordings below).

Note: Python deepagents excludes all non-text blocks; JS keeps evicting large text file blocks because existing tests require it. Happy to align if you'd prefer.

AI use: written with Claude Code; I reviewed every change and verified it as above.

Evidence: a real Deep Agents chat app (createDeepAgent with default filesystem middleware + the real Playwright MCP server via @langchain/mcp-adapters). The agent opens a page and takes a screenshot. The model is a stand-in that reports exactly which content blocks reached it (no API key in my recording environment); everything else is the real stack. Left pane: the app server and which deepagents build it runs.

Before (main @ 389e8da): the screenshot result is evicted to /large_tool_results/… and the model gets a text preview, no image.

video.mp4

After (this branch): the tool result reaches the model as text + image; nothing is evicted.

video.mp4

Image, audio and video blocks a tool returns no longer count toward toolTokenLimitBeforeEvict, and they stay on the replacement message when the tool result's text is evicted.

Fixes langchain-ai#947
@vercel

vercel Bot commented Oct 12, 2026

Copy link
Copy Markdown

Raunak Burrows (@burrows99) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c777fda

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 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

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

deepagents

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

@langchain/sandbox-standard-tests

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

@langchain/daytona

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

@langchain/deno

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

@langchain/modal

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

@langchain/node-vfs

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

@langchain/quickjs

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

commit: c777fda

@burrows99
Raunak Burrows (burrows99) marked this pull request as ready for review October 12, 2026 13:26
…ps-media

# Conflicts:
#	libs/deepagents/src/middleware/fs.eviction.test.ts
#	libs/deepagents/src/middleware/fs.ts
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.
@burrows99 Raunak Burrows (burrows99) changed the title fix(deepagents): keep media blocks out of tool result eviction fix(deepagents): keep audio and video blocks out of tool result eviction Nov 24, 2026

This branch has not been deployed

No deployments
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.

Tool result eviction counts image blocks as text and drops the image

1 participant