From eb9f0005a9023103702df331cc3043a5f5bea96a Mon Sep 17 00:00:00 2001 From: Vigilans Date: Mon, 20 Apr 2026 18:20:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20address=20Greptile=20review=20=E2=80=94?= =?UTF-8?q?=20assert=20mock=20called,=20add=20auto-summary=20check,=20form?= =?UTF-8?q?at?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../messages/handler.py | 8 +++- .../responses_adapters/handler.py | 11 +++++- litellm/responses/main.py | 13 ++++++- .../test_force_reasoning_effort.py | 39 +++++++++---------- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py index d772b17d3cc..2b140c36fc1 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py @@ -443,7 +443,9 @@ def anthropic_messages_handler( ) force_reasoning_effort = litellm_params.force_reasoning_effort if force_reasoning_effort: - output_config = anthropic_messages_optional_request_params.get("output_config") or {} + output_config = ( + anthropic_messages_optional_request_params.get("output_config") or {} + ) anthropic_messages_optional_request_params["output_config"] = { **output_config, "effort": force_reasoning_effort, @@ -451,7 +453,9 @@ def anthropic_messages_handler( # Effort alone does not trigger reasoning — force-enable thinking too thinking = anthropic_messages_optional_request_params.get("thinking") if not isinstance(thinking, dict) or thinking.get("type") == "disabled": - anthropic_messages_optional_request_params["thinking"] = {"type": "adaptive"} + anthropic_messages_optional_request_params["thinking"] = { + "type": "adaptive" + } return base_llm_http_handler.anthropic_messages_handler( model=model, diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py index 3fabc9c51ea..4fc898ecdda 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py @@ -99,10 +99,17 @@ def _build_responses_kwargs( if force_reasoning_effort: reasoning = responses_kwargs.get("reasoning") if isinstance(reasoning, dict): - responses_kwargs["reasoning"] = {**reasoning, "effort": force_reasoning_effort} + responses_kwargs["reasoning"] = { + **reasoning, + "effort": force_reasoning_effort, + } else: responses_kwargs["reasoning"] = { - **({"summary": "detailed"} if is_reasoning_auto_summary_enabled() else {}), + **( + {"summary": "detailed"} + if is_reasoning_auto_summary_enabled() + else {} + ), "effort": force_reasoning_effort, } diff --git a/litellm/responses/main.py b/litellm/responses/main.py index 5cf5d295cb0..bbd36527d92 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -868,7 +868,18 @@ def responses( if isinstance(reasoning, dict): reasoning = {**reasoning, "effort": force_reasoning_effort} else: - reasoning = {"effort": force_reasoning_effort} + from litellm.llms.anthropic.experimental_pass_through.utils import ( + is_reasoning_auto_summary_enabled, + ) + + reasoning = { + **( + {"summary": "detailed"} + if is_reasoning_auto_summary_enabled() + else {} + ), + "effort": force_reasoning_effort, + } local_vars["reasoning"] = reasoning # Get ResponsesAPIOptionalRequestParams with only valid parameters response_api_optional_params: ResponsesAPIOptionalRequestParams = ( diff --git a/tests/test_litellm/test_force_reasoning_effort.py b/tests/test_litellm/test_force_reasoning_effort.py index d75f4d4c33c..04617030612 100644 --- a/tests/test_litellm/test_force_reasoning_effort.py +++ b/tests/test_litellm/test_force_reasoning_effort.py @@ -269,14 +269,13 @@ class TestAnthropicMessagesForceReasoningEffort: except (ValueError, TypeError, AttributeError): pass - if mock_handler.called: - call_kwargs = mock_handler.call_args - optional_params = call_kwargs.kwargs.get( - "anthropic_messages_optional_request_params", {} - ) - assert optional_params.get("output_config", {}).get("effort") == "high" - # thinking should be enabled when not already set - assert optional_params.get("thinking") == {"type": "adaptive"} + assert mock_handler.called, "mock handler was not called — test is a no-op" + call_kwargs = mock_handler.call_args + optional_params = call_kwargs.kwargs.get( + "anthropic_messages_optional_request_params", {} + ) + assert optional_params.get("output_config", {}).get("effort") == "high" + assert optional_params.get("thinking") == {"type": "adaptive"} def test_force_preserves_existing_thinking_config(self): """force_reasoning_effort should not override existing enabled thinking config.""" @@ -299,18 +298,18 @@ class TestAnthropicMessagesForceReasoningEffort: except (ValueError, TypeError, AttributeError): pass - if mock_handler.called: - call_kwargs = mock_handler.call_args - optional_params = call_kwargs.kwargs.get( - "anthropic_messages_optional_request_params", {} - ) - assert optional_params.get("output_config", {}).get("effort") == "high" - # Pre-existing enabled thinking should be preserved - thinking = optional_params.get("thinking", {}) - assert ( - thinking.get("type") != "adaptive" - or thinking.get("type") == "enabled" - ) + assert mock_handler.called, "mock handler was not called — test is a no-op" + call_kwargs = mock_handler.call_args + optional_params = call_kwargs.kwargs.get( + "anthropic_messages_optional_request_params", {} + ) + assert optional_params.get("output_config", {}).get("effort") == "high" + # Pre-existing enabled thinking should be preserved + thinking = optional_params.get("thinking", {}) + assert ( + thinking.get("type") != "adaptive" + or thinking.get("type") == "enabled" + ) # ---------------------------------------------------------------------------