You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
feat: Update event_converter used in A2ARemote agent to use a2a_task.status.message only if parts are non-empty
PiperOrigin-RevId: 846413612
This commit is contained in:
committed by
Copybara-Service
parent
f1eb1c0254
commit
e4ee9d7c46
@@ -229,7 +229,11 @@ def convert_a2a_task_to_event(
|
||||
message = Message(
|
||||
message_id="", role=Role.agent, parts=a2a_task.artifacts[-1].parts
|
||||
)
|
||||
elif a2a_task.status and a2a_task.status.message:
|
||||
elif (
|
||||
a2a_task.status
|
||||
and a2a_task.status.message
|
||||
and a2a_task.status.message.parts
|
||||
):
|
||||
message = a2a_task.status.message
|
||||
elif a2a_task.history:
|
||||
message = a2a_task.history[-1]
|
||||
|
||||
@@ -773,13 +773,9 @@ class TestA2AToEventConverters:
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_task_to_event
|
||||
|
||||
# Create mock message and task
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_status = Mock()
|
||||
mock_status.message = mock_message
|
||||
mock_task = Mock(spec=Task)
|
||||
mock_task.artifacts = None
|
||||
mock_task.status = mock_status
|
||||
mock_task.history = []
|
||||
mock_message = Mock(spec=Message, parts=[Mock()])
|
||||
mock_status = Mock(message=mock_message)
|
||||
mock_task = Mock(spec=Task, artifacts=None, status=mock_status, history=[])
|
||||
|
||||
# Mock the convert_a2a_message_to_event function to raise an exception
|
||||
with patch(
|
||||
@@ -798,11 +794,9 @@ class TestA2AToEventConverters:
|
||||
# Create mock parts and message with valid genai Part
|
||||
mock_a2a_part = Mock()
|
||||
mock_genai_part = genai_types.Part(text="test content")
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.return_value = mock_genai_part
|
||||
mock_convert_part = Mock(return_value=mock_genai_part)
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part]
|
||||
mock_message = Mock(spec=Message, parts=[mock_a2a_part])
|
||||
|
||||
result = convert_a2a_message_to_event(
|
||||
mock_message,
|
||||
@@ -829,11 +823,9 @@ class TestA2AToEventConverters:
|
||||
mock_a2a_part = Mock()
|
||||
mock_genai_part1 = genai_types.Part(text="part 1")
|
||||
mock_genai_part2 = genai_types.Part(text="part 2")
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.return_value = [mock_genai_part1, mock_genai_part2]
|
||||
mock_convert_part = Mock(return_value=[mock_genai_part1, mock_genai_part2])
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part]
|
||||
mock_message = Mock(spec=Message, parts=[mock_a2a_part])
|
||||
|
||||
# Act
|
||||
result = convert_a2a_message_to_event(
|
||||
@@ -855,13 +847,10 @@ class TestA2AToEventConverters:
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_message_to_event
|
||||
|
||||
# Create mock parts and message
|
||||
mock_a2a_part = Mock()
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part]
|
||||
mock_message = Mock(spec=Message, parts=[Mock()])
|
||||
|
||||
# Mock the part conversion to return None to simulate long-running tool detection logic
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.return_value = None
|
||||
mock_convert_part = Mock(return_value=None)
|
||||
|
||||
# Patch the long-running tool detection since the main logic is in the actual conversion
|
||||
with patch(
|
||||
@@ -884,8 +873,7 @@ class TestA2AToEventConverters:
|
||||
"""Test conversion with empty parts list."""
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_message_to_event
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = []
|
||||
mock_message = Mock(spec=Message, parts=[])
|
||||
|
||||
result = convert_a2a_message_to_event(
|
||||
mock_message, "test-author", self.mock_invocation_context
|
||||
@@ -910,11 +898,9 @@ class TestA2AToEventConverters:
|
||||
|
||||
# Setup mock to return None (conversion failure)
|
||||
mock_a2a_part = Mock()
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.return_value = None
|
||||
mock_convert_part = Mock(return_value=None)
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part]
|
||||
mock_message = Mock(spec=Message, parts=[mock_a2a_part])
|
||||
|
||||
result = convert_a2a_message_to_event(
|
||||
mock_message,
|
||||
@@ -939,14 +925,14 @@ class TestA2AToEventConverters:
|
||||
mock_a2a_part2 = Mock()
|
||||
mock_genai_part = genai_types.Part(text="successful conversion")
|
||||
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.side_effect = [
|
||||
Exception("Conversion failed"), # First part fails
|
||||
mock_genai_part, # Second part succeeds
|
||||
]
|
||||
mock_convert_part = Mock(
|
||||
side_effect=[
|
||||
Exception("Conversion failed"), # First part fails
|
||||
mock_genai_part, # Second part succeeds
|
||||
]
|
||||
)
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part1, mock_a2a_part2]
|
||||
mock_message = Mock(spec=Message, parts=[mock_a2a_part1, mock_a2a_part2])
|
||||
|
||||
result = convert_a2a_message_to_event(
|
||||
mock_message,
|
||||
@@ -967,13 +953,10 @@ class TestA2AToEventConverters:
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_message_to_event
|
||||
|
||||
# Create mock parts and message
|
||||
mock_a2a_part = Mock()
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = [mock_a2a_part]
|
||||
mock_message = Mock(spec=Message, parts=[Mock()])
|
||||
|
||||
# Mock the part conversion to return None
|
||||
mock_convert_part = Mock()
|
||||
mock_convert_part.return_value = None
|
||||
mock_convert_part = Mock(return_value=None)
|
||||
|
||||
result = convert_a2a_message_to_event(
|
||||
mock_message,
|
||||
@@ -994,8 +977,7 @@ class TestA2AToEventConverters:
|
||||
"""Test conversion with default author and no invocation context."""
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_message_to_event
|
||||
|
||||
mock_message = Mock(spec=Message)
|
||||
mock_message.parts = []
|
||||
mock_message = Mock(spec=Message, parts=[])
|
||||
|
||||
# Mock UUID generation
|
||||
mock_uuid.return_value = "generated-uuid"
|
||||
|
||||
Reference in New Issue
Block a user