Repository navigation
Closed
Labels
Description
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
- Before condensation: Events are consistent (all have thinking or all don't)
- Condensation runs: Keeps some events, drops others
- After condensation: Mixed state - some ActionEvents have thinking blocks, some don't
- These convert to assistant messages with inconsistent thinking blocks
- 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
Activity
csmith49 commentedon Dec 18, 2025
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.
Fix thinking block consistency after condensation
Fix thinking block consistency for non-batch events
csmith49 commentedon Dec 24, 2025
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:assistantmessage on their own),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
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.