From 3efd070c95a046394390ee722d39be8f4de2c533 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Tue, 29 Sep 2026 03:08:42 +0000 Subject: [PATCH] fix(responses): attach accumulated reasoning items to raw-dict callback choices --- .../transformation.py | 6 +++++ ...responses_transformation_transformation.py | 24 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py index ebd5bac82bc..092adf57ab7 100644 --- a/litellm/completion_extras/litellm_responses_transformation/transformation.py +++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py @@ -780,6 +780,12 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): elif handle_raw_dict_callback is not None: choice, index = handle_raw_dict_callback(item=raw_item, index=index) if choice is not None: + if pending_reasoning_items: + choice.message.reasoning_items = _as_chat_reasoning_items(pending_reasoning_items) + if reasoning_content: + choice.message.reasoning_content = reasoning_content + pending_reasoning_items.clear() + reasoning_content = None choices.append(choice) else: pass # don't fail request if item in list is not supported diff --git a/tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py index 2e1758aada2..611d2f88e7b 100644 --- a/tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py +++ b/tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py @@ -4405,6 +4405,25 @@ def test_map_optional_params_verbosity_merges_into_text(): "message", id="multiple_reasoning_items_before_output_message", ), + pytest.param( + [ + { + "type": "reasoning", + "id": "rs_raw_1", + "summary": [{"type": "summary_text", "text": "Raw Step 1"}], + "encrypted_content": "enc_raw", + }, + { + "type": "message", + "role": "assistant", + "content": [{"type": "output_text", "text": "Raw response text"}], + }, + ], + ["rs_raw_1"], + "Raw Step 1", + "raw_dict_message", + id="reasoning_items_before_raw_dict_message", + ), pytest.param( [ { @@ -4446,7 +4465,10 @@ def test_convert_response_output_to_choices_preserves_all_reasoning_items( ) handler: Final = LiteLLMResponsesTransformationHandler() - choices: Final = handler._convert_response_output_to_choices(items_to_pass) + choices: Final = handler._convert_response_output_to_choices( + items_to_pass, + handle_raw_dict_callback=handler._handle_raw_dict_response_item, + ) assert len(choices) == 1 msg = choices[0].message