Skip to content

fix(deepagents): degrade unsupported binaries in read_file instead of crashing the run - #649

Open
Kamal Gurbanov (kamaalg) wants to merge 1 commit into
langchain-ai:mainfrom
kamaalg:fix/read-file-unsupported-binaries
Open

Kamal Gurbanov (kamaalg) wants to merge 1 commit into
langchain-ai:mainfrom
kamaalg:fix/read-file-unsupported-binaries

Conversation

@kamaalg

@kamaalg Kamal Gurbanov (kamaalg) commented Jul 6, 2026

Copy link
Copy Markdown

Problem

The built-in read_file tool (in createFilesystemMiddleware) returns any non-text binary that isn't image/audio/video as a { type: "file", mimeType, data } content block:

// libs/deepagents/src/middleware/fs.ts (before)
return [{ type: "file", mimeType, data: base64Data }];

For every MIME type except application/pdf, that block cannot be delivered to the model provider:

  • Anthropic wraps it as a base64 document, whose media_type must be application/pdf. It returns a hard 400 and the whole turn fails:

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

  • OpenAI and OpenRouter only accept PDF (and images) via input_file, so they reject it too.

So the moment a deep agent reads a .docx / .pptx / .xlsx — or any file that resolves to application/octet-stream — the entire run aborts. This is easy to hit in practice (e.g. an agent documenting a repository that happens to contain office files). It surfaced downstream in openwiki, which uses the stock read_file tool.

Fix

Keep emitting a file block only for application/pdf — the one binary document type accepted across providers — and degrade any other binary to a short text note (path, MIME type, size). The agent gets a model-safe, useful result and continues instead of crashing. As a bonus, this avoids pushing large, unusable base64 blobs into the context window.

Tests

Added a read_file binary handling suite:

  • office doc (.pptx) → text note, no file block
  • unknown binary (application/octet-stream) → text note
  • PDF → still a file block
  • image → still an image block

vitest run src/middleware/fs.test.ts63 passed, no type errors. oxlint and oxfmt --check clean. Changeset included (deepagents: patch).

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8fe9dc9

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 6, 2026

Copy link
Copy Markdown

Someone 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 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

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

deepagents

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

@langchain/sandbox-standard-tests

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

@langchain/daytona

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

@langchain/deno

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

@langchain/modal

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

@langchain/node-vfs

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

@langchain/quickjs

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

commit: 8fe9dc9

… crashing

read_file returned every non-text, non-image/audio/video binary as a
{ type: "file" } content block. For any MIME type other than
application/pdf this yields a provider request that is rejected:
Anthropic fails the whole turn with
`messages.N...document.source.base64.media_type: Input should be
'application/pdf'`, and OpenAI/OpenRouter only accept PDF (and images)
via input_file. Reading a .docx/.pptx/.xlsx — or any
application/octet-stream file — therefore aborted the entire agent run.

read_file now emits a `file` block only for PDFs (the one document type
accepted across providers) and degrades other binaries to a short text
note, so the agent can keep going. Adds tests covering office-doc and
octet-stream degradation plus PDF/image passthrough.
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