Skip to content

fix(deepagents): avoid non-standard 'file' content block for binary files#651

Open
Robin (robinv8) wants to merge 3 commits into
langchain-ai:mainfrom
robinv8:fix/read-file-binary-openai-compatible
Open

fix(deepagents): avoid non-standard 'file' content block for binary files#651
Robin (robinv8) wants to merge 3 commits into
langchain-ai:mainfrom
robinv8:fix/read-file-binary-openai-compatible

Conversation

@robinv8

Copy link
Copy Markdown

Problem

When a binary file (e.g. PDF, archive, executable) is read via the read_file tool, the middleware returns a content block with type: "file". This content block is not part of the OpenAI chat completions message format and is rejected by OpenAI-compatible providers such as DeepSeek:

As a result, agents using these providers crash as soon as they encounter a non-media binary file.

Change

For binary files that are not image/audio/video, fall back to a type: "text" placeholder that preserves the MIME type and byte size metadata, while omitting the base64 payload. Image/audio/video blocks continue to be returned as before because providers that support vision/audio understand those block types.

Test coverage

Added two unit tests in fs.test.ts:

  • Non-media binary files (PDF) now return a text placeholder.
  • Image files continue to return an image block.

◇ injected env (0) from ../../.env // tip: ⌁ auth for agents [www.vestauth.com]

RUN v4.1.9 /private/tmp/deepagentsjs-fork/libs/deepagents

✓ src/middleware/fs.test.ts (61 tests) 25ms

Test Files 1 passed (1)
Tests 61 passed (61)
Type Errors no errors
Start at 11:28:19
Duration 324ms (transform 69ms, setup 0ms, import 242ms, tests 25ms, environment 0ms)

Checklist

  • Code follows the project style
  • Tests added for the fix
  • Relevant file(s) changed only

OpenAI-compatible providers such as DeepSeek reject the non-standard
`type: "file"` content block produced by read_file for binary files
(e.g. PDFs). Fall back to a text placeholder that preserves the MIME
type and size metadata while keeping the request compatible.

Fixes errors like:
  unknown variant `file`, expected `text` at line 1 column ...
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7015d8c

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

Copy link
Copy Markdown

Robin (@robinv8) 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 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

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

deepagents

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

@langchain/sandbox-standard-tests

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

@langchain/daytona

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

@langchain/deno

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

@langchain/modal

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

@langchain/node-vfs

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

@langchain/quickjs

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

commit: 7015d8c

@robinv8 Robin (robinv8) force-pushed the fix/read-file-binary-openai-compatible branch from 582b6b6 to fb7a585 Compare July 7, 2026 03:37
@robinv8 Robin (robinv8) force-pushed the fix/read-file-binary-openai-compatible branch from fb7a585 to 45ba254 Compare July 7, 2026 03:46
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