From 3cbf11da7191ee0bf72fbd3dbbfa7490a6f0276a Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Fri, 26 Dec 2025 14:39:16 +0800 Subject: [PATCH] fix(chatcmpl): include explicit content=None on assistant tool-call messages --- src/agents/models/chatcmpl_converter.py | 1 + tests/test_openai_chatcompletions_converter.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/agents/models/chatcmpl_converter.py b/src/agents/models/chatcmpl_converter.py index c1f88d437..f9ac43290 100644 --- a/src/agents/models/chatcmpl_converter.py +++ b/src/agents/models/chatcmpl_converter.py @@ -393,6 +393,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam: nonlocal current_assistant_msg, pending_thinking_blocks if current_assistant_msg is None: current_assistant_msg = ChatCompletionAssistantMessageParam(role="assistant") + current_assistant_msg["content"] = None current_assistant_msg["tool_calls"] = [] return current_assistant_msg diff --git a/tests/test_openai_chatcompletions_converter.py b/tests/test_openai_chatcompletions_converter.py index 838c0eeed..2dd84ae5b 100644 --- a/tests/test_openai_chatcompletions_converter.py +++ b/tests/test_openai_chatcompletions_converter.py @@ -370,6 +370,11 @@ def test_tool_call_conversion(): tool_msg = messages[0] assert tool_msg["role"] == "assistant" assert tool_msg.get("content") is None + + # Verify the content key exists in the message even when it is None. + # This is for Chat Completions API compatibility. + assert "content" in tool_msg, "content key should be present in assistant message" + tool_calls = list(tool_msg.get("tool_calls", [])) assert len(tool_calls) == 1