Repository navigation
fix(deepagents): keep audio and video blocks out of tool result eviction - #951
Open
Raunak Burrows (burrows99) wants to merge 4 commits into
Open
Raunak Burrows (burrows99) wants to merge 4 commits into
Raunak Burrows (burrows99) wants to merge 4 commits into
Conversation
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
|
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 detectedLatest commit: c777fda The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
deepagents-acp
deepagents
@langchain/sandbox-standard-tests
@langchain/daytona
@langchain/deno
@langchain/modal
@langchain/node-vfs
@langchain/quickjs
commit: |
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/buildEvictedContentas 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.ts33 passing,oxlintandoxfmt --checkclean. 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),createFilesystemMiddlewaremeasured the result withstringifyToolContent, whichJSON.stringifys the image block. The base64 alone always crossedtoolTokenLimitBeforeEvict, 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
buildEvictedHumanContentalready handles human messages. File and document blocks are still counted and evicted as before, which the existing tests cover.How I verified it:
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:unitin libs/deepagents (1652 passing),oxlint,oxfmt --check.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 (
createDeepAgentwith 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