Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(responses): keep custom_tool_call echoes on their advertised short name

Mateo Wanga64a83bf3625
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py
index 42aea1d0e62..2a253eae0ac 100644
--- a/litellm/responses/litellm_completion_transformation/transformation.py
+++ b/litellm/responses/litellm_completion_transformation/transformation.py
@@ -1225,11 +1225,12 @@ class LiteLLMCompletionResponsesConfig:
raw_arguments = json.dumps({"content": raw_input}) if raw_input else ""
raw_name: Final = function_call.get("name") or ""
namespace: Final = function_call.get("namespace") or ""
+ qualify: Final = bool(namespace) and function_call.get("type") != "custom_tool_call"
tool_call: Final = ChatCompletionToolCallChunk(
id=function_call.get("call_id") or function_call.get("id") or "",
type="function",
function=ChatCompletionToolCallFunctionChunk(
- name=f"{namespace}__{raw_name}" if namespace else raw_name,
+ name=f"{namespace}__{raw_name}" if qualify else raw_name,
arguments=str(raw_arguments or ""),
),
index=0,
diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
index a82bdf40eed..6a89e02aac8 100644
--- a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
@@ -1858,6 +1858,21 @@ class TestToolTransformation:
assert messages[0]["tool_calls"][0]["function"]["name"] == "mcp__everything__get_sum"
+ def test_custom_tool_call_echo_keeps_short_name(self):
+ """Custom tools stay advertised under their short name, so a namespace on
+ a custom_tool_call echo is routing metadata and must not be prefixed."""
+ messages = LiteLLMCompletionResponsesConfig._transform_responses_api_function_call_to_chat_completion_message(
+ function_call={
+ "type": "custom_tool_call",
+ "name": "apply_patch",
+ "namespace": "mcp__everything",
+ "call_id": "call_2",
+ "input": "patch body",
+ }
+ )
+
+ assert messages[0]["tool_calls"][0]["function"]["name"] == "apply_patch"
+
@pytest.mark.parametrize("nested", [True, False])
def test_transform_namespace_tools_preserves_allowed_callers(self, nested):
function_tool = {