Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

fix: handle type-discriminator format in contentBlockFromData#787

Open
kai-agent-free wants to merge 1 commit into
strands-agents:mainfrom
kai-agent-free:fix/content-block-type-fallback
Open

fix: handle type-discriminator format in contentBlockFromData#787
kai-agent-free wants to merge 1 commit into
strands-agents:mainfrom
kai-agent-free:fix/content-block-type-fallback

Conversation

@kai-agent-free

Copy link
Copy Markdown

Problem

Fixes #533

When content blocks are stored in a database (e.g., for session persistence) and then loaded back, the data may have a flat shape with a type discriminator:

{"type": "toolUseBlock", "name": "greet", "toolUseId": "tu_123", "input": {}}

instead of the nested wrapper format that contentBlockFromData expects:

{"toolUse": {"name": "greet", "toolUseId": "tu_123", "input": {}}}

This happens when blocks are spread ({...block}) or when ORMs/storage layers flatten the nested structure.

Solution

Added fallback handling in contentBlockFromData that checks for the type discriminator when the nested wrapper keys aren't found. Supports toolUseBlock, textBlock, and toolResultBlock — the most common block types encountered in session storage.

Tests

Added 3 tests verifying round-trip deserialization from type-discriminator format:

  • ToolUseBlock with type discriminator
  • TextBlock with type discriminator
  • ToolResultBlock with type discriminator

All 66 tests pass.

…s-agents#533)

When content blocks are stored by ORMs or spread ({...block}) instead
of serialized via toJSON(), the data has a flat shape with a type
discriminator (e.g. {type: 'toolUseBlock', name, toolUseId, input})
instead of the nested wrapper ({toolUse: {name, toolUseId, input}}).

This adds fallback handling in contentBlockFromData for ToolUseBlock,
TextBlock, and ToolResultBlock type discriminators, fixing the
'Unknown ContentBlockData type' error when recreating agents from
stored session data.

Fixes strands-agents#533
@strands-agent

Copy link
Copy Markdown
Collaborator

This repository has been merged into the strands-agents/harness-sdk monorepo and will be archived shortly. All new development happens there.

If this PR is still relevant, please recreate it against the monorepo. The code now lives under strands-ts/. Full commit history was preserved, so your base should be findable.

Apologies for the disruption, and thank you for contributing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ToolUse not picked up correctly

2 participants