Skip to content

Comments

fix(deepagents): filter invalid content blocks from subagent ToolMessage#240

Merged
Christian Bromann (christian-bromann) merged 1 commit intomainfrom
cb/tool-use-filtering
Feb 23, 2026
Merged

fix(deepagents): filter invalid content blocks from subagent ToolMessage#240
Christian Bromann (christian-bromann) merged 1 commit intomainfrom
cb/tool-use-filtering

Conversation

@christian-bromann
Copy link
Member

@christian-bromann Christian Bromann (christian-bromann) commented Feb 20, 2026

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

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: 604b64e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@antonnak
Copy link
Contributor

This PR filters tool_use blocks but does not filter thinking or redacted_thinking blocks, which cause the same issue. See #245.

When using Anthropic models, AIMessage.content can be an array containing
tool_use, thinking, and redacted_thinking blocks. Passing these directly
as ToolMessage.content causes downstream errors. Filter out invalid block
types before constructing the ToolMessage, falling back to "Task completed"
if no valid content remains.

Fixes #239, fixes #245
@christian-bromann Christian Bromann (christian-bromann) changed the title fix(deepagents): filter tool_use blocks from subagent ToolMessage content fix(deepagents): filter invalid content blocks from subagent ToolMessage Feb 23, 2026
@christian-bromann
Copy link
Member Author

This PR filters tool_use blocks but does not filter thinking or redacted_thinking blocks, which cause the same issue. See #245.

Anton Nak (@antonnak) thanks for the feedback, added more blocks to the filter list.

@christian-bromann Christian Bromann (christian-bromann) merged commit ad69c39 into main Feb 23, 2026
25 of 26 checks passed
@christian-bromann Christian Bromann (christian-bromann) deleted the cb/tool-use-filtering branch February 23, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants