[PR #240] [MERGED] fix(deepagents): filter invalid content blocks from subagent ToolMessage #289

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

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/240
Author: @christian-bromann
Created: 2/20/2026
Status: Merged
Merged: 2/23/2026
Merged by: @christian-bromann

Base: mainHead: cb/tool-use-filtering


📝 Commits (1)

  • 604b64e fix(deepagents): filter invalid content blocks from subagent ToolMessage

📊 Changes

2 files changed (+329 additions, -2 deletions)

View changed files

📝 libs/deepagents/src/middleware/subagent.test.ts (+305 -0)
📝 libs/deepagents/src/middleware/subagents.ts (+24 -2)

📄 Description

Summary

  • Filter out tool_use, thinking, and redacted_thinking blocks from subagent response content in returnCommandWithStateUpdate before constructing the ToolMessage. When using Anthropic models, AIMessage.content can be an array containing these block types, which are invalid as ToolMessage content and cause downstream errors.
  • Falls back to "Task completed" when filtering removes all content blocks.
  • Adds four unit tests covering: tool_use filtering, thinking/redacted_thinking filtering, mixed-invalid-block fallback, and string passthrough.

Fixes #239, fixes #245


🔄 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/240 **Author:** [@christian-bromann](https://github.com/christian-bromann) **Created:** 2/20/2026 **Status:** ✅ Merged **Merged:** 2/23/2026 **Merged by:** [@christian-bromann](https://github.com/christian-bromann) **Base:** `main` ← **Head:** `cb/tool-use-filtering` --- ### 📝 Commits (1) - [`604b64e`](https://github.com/langchain-ai/deepagentsjs/commit/604b64e0d840c0c3a142d6034a253387a693bc06) fix(deepagents): filter invalid content blocks from subagent ToolMessage ### 📊 Changes **2 files changed** (+329 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/src/middleware/subagent.test.ts` (+305 -0) 📝 `libs/deepagents/src/middleware/subagents.ts` (+24 -2) </details> ### 📄 Description ## Summary - Filter out `tool_use`, `thinking`, and `redacted_thinking` blocks from subagent response content in `returnCommandWithStateUpdate` before constructing the `ToolMessage`. When using Anthropic models, `AIMessage.content` can be an array containing these block types, which are invalid as `ToolMessage` content and cause downstream errors. - Falls back to `"Task completed"` when filtering removes all content blocks. - Adds four unit tests covering: `tool_use` filtering, `thinking`/`redacted_thinking` filtering, mixed-invalid-block fallback, and string passthrough. Fixes #239, fixes #245 --- <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:31 -04:00
yindo closed this issue 2026-06-05 17:22:31 -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#289