Skip to content

fix(deepagents): handle non-string content blocks in tool result sizechecking#288

Open
Christian Bromann (christian-bromann) wants to merge 3 commits intomainfrom
cb/evict-large-toolmessages
Open

fix(deepagents): handle non-string content blocks in tool result sizechecking#288
Christian Bromann (christian-bromann) wants to merge 3 commits intomainfrom
cb/evict-large-toolmessages

Conversation

@christian-bromann

Fixes #277

The tool result eviction logic in processToolMessage only checked content when it was a plain string (typeof msg.content === "string"), which meant array-based content blocks (e.g. [{ type: "text", text: "..." }]) bypassed the size limit entirely and were sent back to the agent untruncated.

The fix uses the existing BaseMessage.text getter from @langchain/core, which already handles both content formats:

  • String content: returned as-is
  • Array content blocks: joins all blocks with type === "text" into a single string

This avoids introducing any new utility functions — the upstream API already solves this.

Changes

  • Updated processToolMessage() in fs.ts to use msg.text instead of directly checking msg.content
  • Added 2 unit tests covering array-based content block eviction (large and small)

… checking (#277)

The eviction logic only checked `content` when it was a plain string,
so array-based content blocks (e.g. `[{ type: "text", text: "..." }]`)
bypassed the size limit entirely. Use the BaseMessage `.text` getter
which already handles both formats.

fixes #277
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: 80fdaf0

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

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.

Large tool results not checked for content length if using non-string content blocks

1 participant