From fa8804ad9c3f21dad3143418c7d9f40190f609ae Mon Sep 17 00:00:00 2001 From: Andrew Xia Date: Mon, 1 Dec 2025 18:11:35 -0800 Subject: [PATCH] [responsesAPI][4] fix responseOutputItem Kimi K2 thinking bug (#29555) Signed-off-by: Andrew Xia Co-authored-by: Andrew Xia --- tests/entrypoints/test_responses_utils.py | 21 +++++++++++++++++++++ vllm/entrypoints/responses_utils.py | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/entrypoints/test_responses_utils.py b/tests/entrypoints/test_responses_utils.py index 893d806b6574..3951bd484008 100644 --- a/tests/entrypoints/test_responses_utils.py +++ b/tests/entrypoints/test_responses_utils.py @@ -5,6 +5,8 @@ import pytest from openai.types.responses.response_function_tool_call_output_item import ( ResponseFunctionToolCallOutputItem, ) +from openai.types.responses.response_output_message import ResponseOutputMessage +from openai.types.responses.response_output_text import ResponseOutputText from openai.types.responses.response_reasoning_item import ( Content, ResponseReasoningItem, @@ -101,3 +103,22 @@ class TestResponsesUtils: ) with pytest.raises(ValueError): construct_chat_message_with_tool_call(item) + + output_item = ResponseOutputMessage( + id="msg_bf585bbbe3d500e0", + content=[ + ResponseOutputText( + annotations=[], + text="dongyi", + type="output_text", + logprobs=None, + ) + ], + role="assistant", + status="completed", + type="message", + ) + + formatted_item = construct_chat_message_with_tool_call(output_item) + assert formatted_item["role"] == "assistant" + assert formatted_item["content"] == "dongyi" diff --git a/vllm/entrypoints/responses_utils.py b/vllm/entrypoints/responses_utils.py index 07abb80ebc9e..2e01cb038af8 100644 --- a/vllm/entrypoints/responses_utils.py +++ b/vllm/entrypoints/responses_utils.py @@ -97,13 +97,18 @@ def construct_chat_message_with_tool_call( "role": "assistant", "reasoning": reasoning_content, } + elif isinstance(item, ResponseOutputMessage): + return { + "role": "assistant", + "content": item.content[0].text, + } elif isinstance(item, ResponseFunctionToolCallOutputItem): return ChatCompletionToolMessageParam( role="tool", content=item.output, tool_call_id=item.call_id, ) - elif item.get("type") == "function_call_output": + elif isinstance(item, dict) and item.get("type") == "function_call_output": # Append the function call output as a tool message. return ChatCompletionToolMessageParam( role="tool",