Skip to content

If an assistant message contains any thinking blocks, the first block must be thinking or redacted_thinking #738

Closed

Description

@xingyaoww
    raise e  # it's already mapped
    ^^^^^^^
  File "/Users/xingyaow/.cache/uv/archive-v0/7syNfyMibYRIdkqALTht7/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 290, in exception_type
    extract_and_raise_litellm_exception(
  File "/Users/xingyaow/.cache/uv/archive-v0/7syNfyMibYRIdkqALTht7/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 165, in extract_and_raise_litellm_exception
    raise raised_exception_obj(
litellm.exceptions.BadRequestError: litellm.BadRequestError: Error code: 400 - {'error': {'message': 'litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"messages.5.content.0: If an assistant message contains any thinking blocks, the first block must be `thinking` or `redacted_thinking`. Found `tool_use`."},"request_id":"req_011CU7kqVmSUn8XEfzjx33MH"}No fallback model group found for original model_group=claude-sonnet-4-5-20250929. Fallbacks=[{\'qwen3-coder-480b\': [\'qwen3-coder-480b-or\']}, {\'glm-4.5\': [\'glm-4.5-or\']}]. Received Model Group=claude-sonnet-4-5-20250929\nAvailable Model Group Fallbacks=None\nError doing the fallback: litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"messages.5.content.0: If an assistant message contains any thinking blocks, the first block must be `thinking` or `redacted_thinking`. Found `tool_use`."},"request_id":"req_011CU7kqVmSUn8XEfzjx33MH"}No fallback model group found for original model_group=claude-sonnet-4-5-20250929. Fallbacks=[{\'qwen3-coder-480b\': [\'qwen3-coder-480b-or\']}, {\'glm-4.5\': [\'glm-4.5-or\']}] LiteLLM Retried: 1 times, LiteLLM Max Retries: 2', 'type': None, 'param': None, 'code': '400'}}

The conversation dump: c211c69a-9c5c-4f7c-a1be-1b7037001bca.zip

Way to reproduce this:

  1. reload conversation and then conversation.run()

Activity

  1. added
    bug
    on Oct 14, 2025
  2. ryanhoangt commented on Oct 15, 2025

    @ryanhoangt
    Member

    I think the root cause might be that interleaved thinking requires us to pass back previous thinking blocks, and in that trajectory when the condenser activated, there was a chat completion with a thinking block that broke into 4 consecutive action events, e.g. E44 to E47. Only E44 contains the thinking block, but the condenser eliminated all events up to E46, and when we pass back E47 only, the thinking block is missing and causes 400 error.

    Image

    It might be a bit tricky to get it work reliably, one possible solution might be to copy the thinking block to all action events with the same completion id and filter duplicate when combining.

  3. ryanhoangt commented on Oct 17, 2025

    @ryanhoangt
    Member

    Way to repro: In the 14_context_condenser.py example, you can change max_size of the condenser from 10 to 14 and append the first task message with IMPORTANT: ALWAYS generate 3 ACTIONS at once to save interactions. -- then you can see it fails consistently after the first condensation request (about event 20).

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions