sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[PORT] Keep unknown content blocks from saved data and leave them out of model requests (TS→Py)

Open strandly-the-agent opened this issue 3 weeks ago • 1 comments

Source SDK

strands-ts

Target SDK

strands-py

Related Files

strands-ts/src/types/messages.ts
strands-ts/src/types/__tests__/messages.test.ts
strands-ts/src/index.ts
strands-ts/src/interrupt.ts
strands-ts/src/__tests__/interrupt.test.ts
strands-ts/src/multiagent/state.ts
strands-ts/src/multiagent/__tests__/state.test.ts
strands-ts/src/agent/__tests__/snapshot.test.ts
strands-ts/src/models/model-proxy.ts
strands-ts/src/models/__tests__/model-proxy.test.ts
strands-ts/src/models/bedrock.ts
strands-ts/src/models/__tests__/bedrock.test.ts
strands-ts/src/models/openai/chat-adapter.ts
strands-ts/src/models/openai/__tests__/chat.test.ts
strands-ts/src/models/openai/responses-adapter.ts
strands-ts/src/models/openai/__tests__/responses.test.ts
strands-ts/src/models/vercel.ts
strands-ts/src/models/__tests__/vercel.test.ts
strands-ts/src/models/__tests__/anthropic.test.ts
strands-ts/src/models/__tests__/google.test.ts
strands-ts/src/models/routing/classifier-strategy.ts
strands-ts/src/__fixtures__/mock-message-model.ts
strands-ts/src/__fixtures__/slim-types.ts

Confirmation

  • [x] The change is complete in the source SDK, and every related artifact is listed above (source, tests, and docs, if the change has any).

Source PR: #5564 (merged 2026-11-10). Its body says "Python follows in a separate PR"; none is open yet.

Gap in Python (verified on main @ b17ae40f3). Restoring a message that holds a block type this version doesn't know already succeeds, since content blocks are plain dicts. The next model call then fails: BedrockModel._format_bedrock_messages, AnthropicModel.format_request and OpenAIModel.format_request all raise TypeError: content_type=<futureBlock> | unsupported type. So a session saved by a newer SDK (the next block is ToolReferenceBlock, #5668) can't be resumed after a rollback, same as TS before #5564.

What the port needs: leave unrecognized blocks (top level and inside a tool result) out of every provider's request instead of raising, give a tool result left with no content the text [unsupported content omitted], and log the "saved by a newer sdk version, upgrade to use it" warning once when loading. Keep the blocks unchanged in history so they save back as they were.

Not ported in the parity run (port gate): Python has no ModelProxy, which is where TS fills unknown-only tool results, so the port must either add a central request filter or change every provider (10 raise unsupported type today). Both are a design decision, and "unknown" has to be defined for TypedDict blocks (a known-key set). This overlaps the cross-SDK unsupported-block policy in #5316.

strandly-the-agent avatar Nov 11 '26 14:11 strandly-the-agent

I'd like to take the Python port. First, a question on the design point the issue leaves open.

My proposal is one central request filter instead of changing all 10 providers:

  • Add a private helper in strands.types.content. It drops a block whose key isn't a ContentBlock key, and inside toolResult.content one whose key isn't a ToolResultContent key. "Known" means the TypedDict's annotation keys, so a new block such as injected (#5977) is covered as soon as it's added to the type. A tool result left empty gets the text [unsupported content omitted].
  • Call it in event_loop.streaming.stream_messages, next to the existing summary rewrite, and in compression.context_compression.generate_summary, which calls model.stream() directly with raw history. It works on the request copy, so history keeps the blocks and saves them back unchanged.
  • Log the "saved by a newer sdk version, upgrade to use it" warning once when saved messages are restored (session, snapshot, interrupt and multi-agent state).
  • Providers keep their unsupported type errors for blocks passed to Model.stream() directly. Making that uniform stays with #5316.

Does a filter at those two call sites work for you, or would you rather have the per-provider change? I'll open the PR once you've picked a direction.

Drafted with AI assistance.

Rutvij97 avatar Nov 12 '26 13:11 Rutvij97