Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agents/models/chatcmpl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_openai_chatcompletions_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down