Skip to content

Commit e6645ee

Browse files
committed
Revert "Gemini client support for messages without role (A2A) (#2358)"
This reverts commit de13b2f.
1 parent 00543b9 commit e6645ee

File tree

2 files changed

+1
-18
lines changed

2 files changed

+1
-18
lines changed

autogen/oai/gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def _oai_messages_to_gemini_messages(self, messages: list[dict[str, Any]]) -> li
632632
rst = []
633633
for message in messages:
634634
parts, part_type = self._oai_content_to_gemini_content(message)
635-
role = "user" if message.get("role", "user") in ["user", "system"] else "model"
635+
role = "user" if message["role"] in ["user", "system"] else "model"
636636

637637
if part_type == "text":
638638
rst.append(

test/oai/test_gemini.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,6 @@ def test_gemini_empty_message_handling(self, gemini_client):
223223
assert converted_messages[-3].parts[0].text == "empty", "Empty message is not converted to 'empty' correctly"
224224
assert converted_messages[-1].parts[0].text == "empty", "Empty message is not converted to 'empty' correctly"
225225

226-
def test_gemini_message_without_role_defaults_to_user(self, gemini_client):
227-
"""Test that messages without a 'role' field default to 'user' role (e.g., A2A messages)."""
228-
messages = [
229-
{"content": "Hello, this message has no role field"},
230-
{"role": "model", "content": "How can I help you?"},
231-
{"content": "Another message without role"},
232-
]
233-
234-
converted_messages = gemini_client._oai_messages_to_gemini_messages(messages)
235-
236-
# Messages without role should be treated as "user"
237-
assert converted_messages[0].role == "user", "Message without role should default to 'user'"
238-
assert converted_messages[0].parts[0].text == "Hello, this message has no role field"
239-
assert converted_messages[1].role == "model"
240-
assert converted_messages[2].role == "user", "Message without role should default to 'user'"
241-
assert converted_messages[2].parts[0].text == "Another message without role"
242-
243226
def test_vertexai_safety_setting_conversion(self):
244227
safety_settings = [
245228
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"},

0 commit comments

Comments
 (0)