From 2d3605619326e53dda24b7e0ccdf610d18ac09f5 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Sat, 31 Oct 2026 18:11:19 -0700 Subject: [PATCH] fix(anthropic): keep defer_loading and allowed_callers on the computer_20251124 chat tool --- litellm/llms/anthropic/chat/transformation.py | 8 ++++++-- .../test_anthropic_chat_transformation.py | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index 6dfac35ddc2..d773e31c733 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -1114,9 +1114,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): if returned_tool is not None: # Only set defer_loading on tools that support it (not tool search tools or computer tools) tool_type = returned_tool.get("type", "") - if not tool_type.startswith("computer_") and tool_type not in ( + if tool_type not in ( "tool_search_tool_regex_20251119", "tool_search_tool_bm25_20251119", + "computer_20241022", + "computer_20250124", ): if _defer_loading is not None: returned_tool["defer_loading"] = _validated_defer_loading(_defer_loading) @@ -1131,9 +1133,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): if returned_tool is not None: # Only set allowed_callers on tools that support it (not tool search tools or computer tools) tool_type = returned_tool.get("type", "") - if not tool_type.startswith("computer_") and tool_type not in ( + if tool_type not in ( "tool_search_tool_regex_20251119", "tool_search_tool_bm25_20251119", + "computer_20241022", + "computer_20250124", ): if _allowed_callers is not None: if not isinstance(_allowed_callers, list) or not all( diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index f161570390f..03711e5c3ce 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -6787,22 +6787,34 @@ def test_eager_input_streaming_not_set_on_computer_use_tool(): assert "eager_input_streaming" not in mapped_tool -@pytest.mark.parametrize("tool_type", ["computer_20241022", "computer_20250124", "computer_20251124"]) -def test_computer_tools_drop_defer_loading_and_allowed_callers(tool_type: str): - computer_tool: Final = { +def _computer_tool_with_defer_loading_and_allowed_callers(tool_type: str) -> dict[str, object]: + return { "type": tool_type, "function": {"name": "computer", "parameters": {"display_width_px": 1024, "display_height_px": 768}}, "defer_loading": True, "allowed_callers": ["code_execution_20250825"], } - mapped_tool, _ = AnthropicConfig().map_tool_helper(computer_tool) + +@pytest.mark.parametrize("tool_type", ["computer_20241022", "computer_20250124"]) +def test_legacy_computer_tools_drop_defer_loading_and_allowed_callers(tool_type: str): + mapped_tool, _ = AnthropicConfig().map_tool_helper(_computer_tool_with_defer_loading_and_allowed_callers(tool_type)) assert mapped_tool["type"] == tool_type assert "defer_loading" not in mapped_tool assert "allowed_callers" not in mapped_tool +def test_computer_20251124_keeps_defer_loading_and_allowed_callers(): + mapped_tool, _ = AnthropicConfig().map_tool_helper( + _computer_tool_with_defer_loading_and_allowed_callers("computer_20251124") + ) + + assert mapped_tool["type"] == "computer_20251124" + assert mapped_tool["defer_loading"] is True + assert mapped_tool["allowed_callers"] == ["code_execution_20250825"] + + def test_eager_input_streaming_reaches_anthropic_request_tools(): result = AnthropicConfig().map_openai_params( non_default_params={"tools": [_eager_chat_tool(eager_input_streaming=True)], "stream": True},