Skip to content

Condenser creates inconsistent thinking blocks causing Claude API errors #1438

Closed

Description

@xingyaoww

Condenser creates inconsistent thinking blocks causing Claude API errors

Symptom

After conversation history condensation, Claude API rejects requests with the following error:

UNKNOWN Event: ConversationErrorEvent: Unknown event type: ConversationErrorEvent 
{'kind': 'ConversationErrorEvent', 'id': 'adac9d93-e3e0-4f4f-8493-4d3b592f994f', 
'timestamp': '2025-12-15T20:30:45.563120', 'source': 'environment', 
'code': 'LLMBadRequestError', 
'detail': 'litellm.BadRequestError: Error code: 400 – 
{\"error\":{\"type\":\"invalid_request_error\",
\"message\":\"messages.5.content.0.type: Expected `thinking` or `redacted_thinking`, 
but found `tool_use`. When `thinking` is enabled, a final `assistant` message must 
start with a thinking block (proceeding the lastmost set of `tool_use` and 
`tool_result` blocks). We recommend you include thinking blocks from previous turns. 
To avoid this requirement, disable `thinking`.

Key parts of error:

  • messages.5.content.0.type: Expected 'thinking' or 'redacted_thinking', but found 'tool_use'
  • When 'thinking' is enabled, a final 'assistant' message must start with a thinking block
  • Occurs after condensation has run

Environment

  • SDK Version: Current main branch (as of Dec 2024)
  • Model: anthropic/claude-sonnet-4-5-20250929 (but likely affects other Claude models)
  • Condensation: Issue occurs after conversation history is condensed

Investigation So Far

Data Analysis

Analyzed event data from the failing conversation:

After condensation:

  • Total ActionEvents remaining: 59
  • ActionEvents WITH thinking blocks: 2 (IDs: 7b7eac38-9555..., 6a54bd83-9ac0...)
  • ActionEvents WITHOUT thinking blocks: 57

Result: MIXED thinking block presence across ActionEvents

Root Cause Hypothesis

  1. Before condensation: Events are consistent (all have thinking or all don't)
  2. Condensation runs: Keeps some events, drops others
  3. After condensation: Mixed state - some ActionEvents have thinking blocks, some don't
  4. These convert to assistant messages with inconsistent thinking blocks
  5. Claude API rejects the request

Reproduction

Event data available at: /workspace/project/cf9590e60fdb43bdbd7914235d4012db.tar.gz

Contains 188 events including:

  • 90 ActionEvents (3 with thinking, 87 without)
  • 2 Condensation events
  • 90 ObservationEvents
  • Other event types

cf9590e60fdb43bdbd7914235d4012db.tar.gz

Activity

  1. added
    bug
    on Dec 18, 2025
  2. csmith49 commented on Dec 18, 2025

    @csmith49
    Contributor

    See also issue #1395. I've got a fix I'm working on (PR #1412) that should address this issue. Almost ready to go, just introduces some pretty big changes to the summarizing condenser logic so I'm doing what I can to test it thoroughly.

  3. added 2 commits that reference this issue on Dec 23, 2025
    e624161
    b76b942
  4. csmith49 commented on Dec 24, 2025

    @csmith49
    Contributor

    The issue is annoyingly subtle.

    The problem isn't that we end up with some action events with thinking blocks and some without after a condensation: the condenser doesn't modify the contents of events, it just drops them and inserts summaries. If there are action events without thinking blocks they must have been there before (and inspecting the events from the issue confirms this).

    The issue also isn't what Anthropic reports (When 'thinking' is enabled, a final 'assistant' message must start with a thinking block). Before condensation, there are event sequences that:

    1. End in an action/observation pair,
    2. Are not part of any other LLM response (and so will be in an assistant message on their own),
    3. Have no thinking block, and
    4. Are followed by a user message.

    The real concept we need to be cognizant of is a tool loop that Anthropic recognizes as a single "turn" of the LLM. This definition is a little bit fuzzy (you can see their docs here) but the idea is that the

    thinking -> tool use -> observation -> tool use -> observation -> ... 
    

    pattern is totally fine even if they are split over different messages.

    I've implemented a fix to make sure the condenser doesn't split these loops up in #1508.

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

Metadata

Metadata

Assignees

Labels

bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions