[PR #278] [CLOSED] fix: handle multi-type content blocks in tool result size checking #324

Closed
opened 2026-06-05 17:22:40 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/278
Author: @bracesproul
Created: 3/5/2026
Status: Closed

Base: mainHead: open-swe/020b364c-2a7f-e2b2-30e0-4593befd0490


📝 Commits (1)

  • 6ba97cb fix: handle multi-type content blocks in tool result size checking

📊 Changes

3 files changed (+73 additions, -4 deletions)

View changed files

📝 libs/deepagents/src/middleware/fs.eviction.test.ts (+39 -0)
📝 libs/deepagents/src/middleware/fs.ts (+33 -4)
📝 libs/deepagents/src/middleware/index.ts (+1 -0)

📄 Description

Description

Fixes a bug where the tool result eviction logic only checked content when it was a plain string, ignoring array-based content blocks (e.g., [{ type: "text", text: "..." }]). This meant that a tool result with complex content blocks containing arbitrarily large text fields would bypass the size limit and be sent directly back to the agent.

The fix introduces an extractTextContent helper that handles both content formats:

  • String content: returned as-is (existing behavior)
  • Array content blocks: joins all blocks with type === "text" and checks the combined length

Changes:

  • Added extractTextContent() utility function in fs.ts
  • Updated processToolMessage() to use extractTextContent() instead of only checking string content
  • Added 6 unit tests for extractTextContent
  • Exported extractTextContent from the middleware index

Resolves https://github.com/langchain-ai/deepagentsjs/issues/277

Test Plan

  • All 499 existing + new tests pass (pnpm test)
  • TypeScript compilation passes (pnpm exec tsc --noEmit)
  • Lint passes (pnpm lint)
  • Format passes (pnpm format)
  • Verify that tool results with array content blocks containing large text are properly evicted
  • Verify that tool results with string content still work as before

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/278 **Author:** [@bracesproul](https://github.com/bracesproul) **Created:** 3/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `open-swe/020b364c-2a7f-e2b2-30e0-4593befd0490` --- ### 📝 Commits (1) - [`6ba97cb`](https://github.com/langchain-ai/deepagentsjs/commit/6ba97cbf572c5f27b79390230db92715b0109d79) fix: handle multi-type content blocks in tool result size checking ### 📊 Changes **3 files changed** (+73 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/src/middleware/fs.eviction.test.ts` (+39 -0) 📝 `libs/deepagents/src/middleware/fs.ts` (+33 -4) 📝 `libs/deepagents/src/middleware/index.ts` (+1 -0) </details> ### 📄 Description ## Description Fixes a bug where the tool result eviction logic only checked `content` when it was a plain string, ignoring array-based content blocks (e.g., `[{ type: "text", text: "..." }]`). This meant that a tool result with complex content blocks containing arbitrarily large `text` fields would bypass the size limit and be sent directly back to the agent. The fix introduces an `extractTextContent` helper that handles both content formats: - **String content**: returned as-is (existing behavior) - **Array content blocks**: joins all blocks with `type === "text"` and checks the combined length Changes: - Added `extractTextContent()` utility function in `fs.ts` - Updated `processToolMessage()` to use `extractTextContent()` instead of only checking string content - Added 6 unit tests for `extractTextContent` - Exported `extractTextContent` from the middleware index Resolves https://github.com/langchain-ai/deepagentsjs/issues/277 ## Test Plan - [x] All 499 existing + new tests pass (`pnpm test`) - [x] TypeScript compilation passes (`pnpm exec tsc --noEmit`) - [x] Lint passes (`pnpm lint`) - [x] Format passes (`pnpm format`) - [ ] Verify that tool results with array content blocks containing large text are properly evicted - [ ] Verify that tool results with string content still work as before --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:40 -04:00
yindo closed this issue 2026-06-05 17:22:40 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#324