diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py index 1a052f457c5..0cf6d15c65b 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py @@ -198,14 +198,16 @@ class LiteLLMAnthropicToResponsesAPIAdapter: @staticmethod def translate_tool_choice_to_responses_api( tool_choice: AnthropicMessagesToolChoice, - ) -> Dict[str, Any]: + ) -> Union[str, Dict[str, Any]]: """Convert Anthropic tool_choice to Responses API tool_choice.""" tc_type = tool_choice.get("type") if tc_type == "any": - return {"type": "required"} + return "required" + elif tc_type == "none": + return "none" elif tc_type == "tool": return {"type": "function", "name": tool_choice.get("name", "")} - return {"type": "auto"} + return "auto" @staticmethod def translate_context_management_to_responses_api( diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py index 14e872485ec..7555d04e648 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py @@ -587,14 +587,20 @@ class TestTranslateToolChoiceToResponsesAPI: """Anthropic tool_choice -> Responses API tool_choice.""" def test_auto_maps_to_auto(self): - assert _ADAPTER.translate_tool_choice_to_responses_api({"type": "auto"}) == { - "type": "auto" - } + assert ( + _ADAPTER.translate_tool_choice_to_responses_api({"type": "auto"}) == "auto" + ) def test_any_maps_to_required(self): - assert _ADAPTER.translate_tool_choice_to_responses_api({"type": "any"}) == { - "type": "required" - } + assert ( + _ADAPTER.translate_tool_choice_to_responses_api({"type": "any"}) + == "required" + ) + + def test_none_maps_to_none(self): + assert ( + _ADAPTER.translate_tool_choice_to_responses_api({"type": "none"}) == "none" + ) def test_specific_tool_maps_to_function(self): result = _ADAPTER.translate_tool_choice_to_responses_api( @@ -603,8 +609,8 @@ class TestTranslateToolChoiceToResponsesAPI: assert result == {"type": "function", "name": "get_weather"} def test_unknown_type_defaults_to_auto(self): - result = _ADAPTER.translate_tool_choice_to_responses_api({"type": "none"}) - assert result == {"type": "auto"} + result = _ADAPTER.translate_tool_choice_to_responses_api({"type": "auto"}) + assert result == "auto" # ---------------------------------------------------------------------------