Skip to content

[FEATURE] Summarize through Anthropic native compaction #5401

Open

Description

@jimbrub

Human Overview

Anthropic's preserved thinking models will return a 400 error when the prefix of a thinking block is changed. In order to keep thinking as a part of the conversation and not dropping thinking, summarization needs to happen through Claude's Native compact API. AnthropicModel overrides Model.compact() so that sessions with these models summarize through native compaction.

SDK Language

Both / Not language-specific

Problem Statement

Offload.summarize replaces older messages with a client-side summary. On preserved-thinking Claude models, that changes the history the kept turns' thinking is bound to, so the next request fails with 400 Invalid signature in thinking block, or drop_block discards the reasoning. This affects context_manager="auto", agentic, and proactive_summarization.

Proposed Solution

Part 1 of design 0022. Override AnthropicModel.compact() with on-demand compaction (compact-2026-09-04):

  • Request settings:
    • compaction.instructions comes from instructions (SummarizeConfig.systemPrompt), capped at 16,384 characters.
    • Use the model's max_tokens. A stop_reason: "max_tokens" result leaves history unchanged.
    • Don't send stop_sequences, output_config.format, or a forced tool_choice (the API rejects them).
    • Don't use threshold compaction (compact_20260112).
  • Gating on serverCompaction:
    • true: native compaction.
    • undefined: try native, and record a capability rejection as false.
    • false: fall back to super.compact(). If historyBound is true, warn and return undefined instead, since a client-side summary would break the thinking.
    • Timeouts, throttles and 5xx errors are never recorded. Warn and return undefined.
  • Until the metadata work lands, the capability comes from a private list of preserved-thinking model IDs (Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5) plus a temporary AnthropicModelConfig.serverCompaction override, mirroring use_native_token_count.
  • Once a compaction block is in history, stream() and countTokens() use beta.messages with the compaction beta.
  • The result is stored as a summary TextBlock with providerData ([FEATURE] Core: providerData on TextBlock for session restore and model switches #5402), with no [Summarized: …] header.

Done when:

Use Case

A long-running agent on Opus 5.5 with Offload.summarize("*").when(utilization=0.8, preserve_recent=4) summarizes and keeps the reasoning in its recent turns, instead of failing or losing it.

Additional Context

Metadata

Metadata

Assignees

Labels

area-contextSession or context relatedarea-modelRelated to models or model providersdesignenhancementNew feature or request

Type

Fields

Language

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions