Skip to content

fix(deepagents): read_file must not emit unsendable document blocks for non-PDF binaries - #647

Open
Idan Shperling (Idan-Shperling) wants to merge 1 commit into
langchain-ai:mainfrom
Idan-Shperling:fix/read-file-non-pdf-binary-document-block
Open

fix(deepagents): read_file must not emit unsendable document blocks for non-PDF binaries#647
Idan Shperling (Idan-Shperling) wants to merge 1 commit into
langchain-ai:mainfrom
Idan-Shperling:fix/read-file-non-pdf-binary-document-block

Conversation

@Idan-Shperling

Copy link
Copy Markdown

Problem

read_file base64-encodes any non-text file into a type: "file" content block, which provider adapters translate into a document block. Provider APIs only accept application/pdf for base64 document blocks, so as soon as an agent reads any other binary file in a repo (fonts, .wasm, archives, .ico, etc.) the request fails:

Error 400 invalid_request_error
messages.N.content.M.tool_result.content.0.document.source.base64.media_type:
Input should be 'application/pdf'

This makes read_file (and thus any deep agent) unusable on repositories that contain non-PDF binaries — the agent only has to read one to hard-fail the run.

Fix

In createReadFileTool (libs/deepagents/src/middleware/fs.ts), gate the type: "file" document block on application/pdf. Any other binary type returns a short text note instead of an unsendable block. image/, audio/, video/ blocks and PDFs are unchanged.

Tests

Added two unit tests in fs.test.ts:

  • non-PDF binary (application/octet-stream) → text note, never a type: "file" block (fails on main).
  • application/pdf → still returns the document block (regression guard).

oxfmt + oxlint clean.

Context

Hit while running OpenWiki (which uses deepagents) against a large repo — the agent read a non-PDF binary and every run 400'd.

…or non-PDF binaries

read_file base64-encodes any non-text file into a `type: "file"` block, which
provider adapters translate into a document block. Provider APIs only accept
`application/pdf` for base64 document blocks, so reading any other binary
(fonts, wasm, archives, etc.) fails with a 400:
`document.source.base64.media_type: Input should be 'application/pdf'`.

Gate the document block on application/pdf and return a short text note for
other binary types. image/audio/video blocks and PDFs are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ef5cde8

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

This PR includes changesets to release 3 packages
Name Type
deepagents Patch
deepagents-acp Patch
@deepagents/evals 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 Jul 5, 2026

Copy link
Copy Markdown

Idan Shperling (@Idan-Shperling) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Jul 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

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

deepagents

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

@langchain/sandbox-standard-tests

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

@langchain/daytona

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

@langchain/deno

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

@langchain/modal

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

@langchain/node-vfs

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

@langchain/quickjs

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

commit: ef5cde8

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.

1 participant