Skip to content

Commit 007a65c

Browse files
authored
Add explicit content=None to assistant tool-call messages in Chat Completions converter (#2238)
1 parent ba55bbd commit 007a65c

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/agents/models/chatcmpl_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
393393
nonlocal current_assistant_msg, pending_thinking_blocks
394394
if current_assistant_msg is None:
395395
current_assistant_msg = ChatCompletionAssistantMessageParam(role="assistant")
396+
current_assistant_msg["content"] = None
396397
current_assistant_msg["tool_calls"] = []
397398

398399
return current_assistant_msg

tests/test_openai_chatcompletions_converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ def test_tool_call_conversion():
370370
tool_msg = messages[0]
371371
assert tool_msg["role"] == "assistant"
372372
assert tool_msg.get("content") is None
373+
374+
# Verify the content key exists in the message even when it is None.
375+
# This is for Chat Completions API compatibility.
376+
assert "content" in tool_msg, "content key should be present in assistant message"
377+
373378
tool_calls = list(tool_msg.get("tool_calls", []))
374379
assert len(tool_calls) == 1
375380

0 commit comments

Comments
 (0)