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

[FEATURE] Core: `providerData` on `TextBlock` for session restore and model switches

Open jimbrub opened this issue 1 month ago • 1 comments

Human Overview

Server-side compaction returns a signed summary that only the producing provider can read. Strands stores it as an ordinary summary TextBlock with a new provider-agnostic providerData field. The block survives session restores and becomes plain text on a model switch. Anthropic (#5401) and OpenAI Responses (#5409) both build on this.

SDK Language

Both / Not language-specific

Problem Statement

A native compaction result is only valid on the provider that produced it, and its signature has to be sent back unchanged. Strands has nowhere to keep that data on a message. A restored session would lose it, and another provider would get a block it can't accept. Context strategies could also edit it and break the signature.

Proposed Solution

Part 1 of design 0022. This replaces the earlier dedicated compaction content block.

  • Add an optional providerData: ProviderData { provider, data } field to TextBlock. Example (Anthropic): {"provider":"anthropic","data":{"type":"compaction","signature":…,"encrypted_content":…}}. The change is additive and backwards compatible.
  • Rules:
    1. Only the producing provider reads providerData. For example, AnthropicModel sends { ...data, content: text }. Every other provider sends text as plain text.
    2. Strategies never edit it. _blockMatchesTarget skips any TextBlock with providerData.
    3. toJSON/fromJSON/contentBlockFromData keep it.
    4. text is the only copy of the summary.
  • Test save and restore with the file, S3, and repository session managers.

Done when:

  • Round-trip unit tests pass in Python and TypeScript.
  • Session restore integ tests pass with the file, S3, and repository session managers.
  • A switch from AnthropicModel to BedrockModel sends plain text. Tests record the expected result: a 400 under prefix_mismatch_behavior: "error", and success under drop_block.

Use Case

An agent that compacted on AnthropicModel resumes from a saved session, or falls back to BedrockModel, and keeps working.

Additional Context

  • Parent epic: #5410
  • Blocks: #5401, #5409
  • Sibling core work: #5464 (Model.compact(), compactionSplitIndex, ContextManager routing)
  • Design: team/designs/0022-server-side-compaction-support.md (#5242)
  • Related: #4270, #4769.

jimbrub avatar Oct 22 '26 14:10 jimbrub

Reopening: design 0022 now stores compactions as a summary TextBlock with providerData instead of a dedicated compaction block. Scope rewritten to match.

jimbrub avatar Oct 23 '26 14:10 jimbrub