Skip to content

Commit 4eb2a11

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: fix bug where remote a2a agent wasn't using its a2a part converter
PiperOrigin-RevId: 836399603
1 parent a1c09b7 commit 4eb2a11

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/google/adk/agents/remote_a2a_agent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ async def _handle_a2a_response(
417417
# This is the initial response for a streaming task or the complete
418418
# response for a non-streaming task, which is the full task state.
419419
# We process this to get the initial message.
420-
event = convert_a2a_task_to_event(task, self.name, ctx)
420+
event = convert_a2a_task_to_event(
421+
task, self.name, ctx, self._a2a_part_converter
422+
)
421423
# for streaming task, we update the event with the task status.
422424
# We update the event as Thought updates.
423425
if task and task.status and task.status.state == TaskState.submitted:
@@ -429,7 +431,7 @@ async def _handle_a2a_response(
429431
):
430432
# This is a streaming task status update with a message.
431433
event = convert_a2a_message_to_event(
432-
update.status.message, self.name, ctx
434+
update.status.message, self.name, ctx, self._a2a_part_converter
433435
)
434436
if event.content and update.status.state in [
435437
TaskState.submitted,
@@ -447,7 +449,9 @@ async def _handle_a2a_response(
447449
# signals:
448450
# 1. append: True for partial updates, False for full updates.
449451
# 2. last_chunk: True for full updates, False for partial updates.
450-
event = convert_a2a_task_to_event(task, self.name, ctx)
452+
event = convert_a2a_task_to_event(
453+
task, self.name, ctx, self._a2a_part_converter
454+
)
451455
else:
452456
# This is a streaming update without a message (e.g. status change)
453457
# or a partial artifact update. We don't emit an event for these
@@ -463,7 +467,9 @@ async def _handle_a2a_response(
463467

464468
# Otherwise, it's a regular A2AMessage for non-streaming responses.
465469
elif isinstance(a2a_response, A2AMessage):
466-
event = convert_a2a_message_to_event(a2a_response, self.name, ctx)
470+
event = convert_a2a_message_to_event(
471+
a2a_response, self.name, ctx, self._a2a_part_converter
472+
)
467473
event.custom_metadata = event.custom_metadata or {}
468474

469475
if a2a_response.context_id:

tests/unittests/agents/test_remote_a2a_agent.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ async def test_handle_a2a_response_success_with_message(self):
723723
mock_a2a_message,
724724
self.agent.name,
725725
self.mock_context,
726+
self.mock_a2a_part_converter,
726727
)
727728
# Check that metadata was added
728729
assert result.custom_metadata is not None
@@ -760,6 +761,7 @@ async def test_handle_a2a_response_with_task_completed_and_no_update(self):
760761
mock_a2a_task,
761762
self.agent.name,
762763
self.mock_context,
764+
self.mock_a2a_part_converter,
763765
)
764766
# Check the parts are not updated as Thought
765767
assert result.content.parts[0].thought is None
@@ -864,6 +866,7 @@ async def test_handle_a2a_response_with_task_submitted_and_no_update(self):
864866
mock_a2a_task,
865867
self.agent.name,
866868
self.mock_context,
869+
self.mock_a2a_part_converter,
867870
)
868871
# Check the parts are updated as Thought
869872
assert result.content.parts[0].thought is True
@@ -909,6 +912,7 @@ async def test_handle_a2a_response_with_task_status_update_with_message(self):
909912
mock_a2a_message,
910913
self.agent.name,
911914
self.mock_context,
915+
self.mock_a2a_part_converter,
912916
)
913917
# Check that metadata was added
914918
assert result.custom_metadata is not None
@@ -954,6 +958,7 @@ async def test_handle_a2a_response_with_task_status_working_update_with_message(
954958
mock_a2a_message,
955959
self.agent.name,
956960
self.mock_context,
961+
self.mock_a2a_part_converter,
957962
)
958963
# Check that metadata was added
959964
assert result.custom_metadata is not None
@@ -1009,7 +1014,10 @@ async def test_handle_a2a_response_with_artifact_update(self):
10091014

10101015
assert result == mock_event
10111016
mock_convert.assert_called_once_with(
1012-
mock_a2a_task, self.agent.name, self.mock_context
1017+
mock_a2a_task,
1018+
self.agent.name,
1019+
self.mock_context,
1020+
self.agent._a2a_part_converter,
10131021
)
10141022
# Check that metadata was added
10151023
assert result.custom_metadata is not None
@@ -1039,13 +1047,16 @@ class TestRemoteA2aAgentMessageHandlingFromFactory:
10391047

10401048
def setup_method(self):
10411049
"""Setup test fixtures."""
1050+
self.mock_a2a_part_converter = Mock()
1051+
10421052
self.agent_card = create_test_agent_card()
10431053
self.agent = RemoteA2aAgent(
10441054
name="test_agent",
10451055
agent_card=self.agent_card,
10461056
a2a_client_factory=ClientFactory(
10471057
config=ClientConfig(httpx_client=httpx.AsyncClient()),
10481058
),
1059+
a2a_part_converter=self.mock_a2a_part_converter,
10491060
)
10501061

10511062
# Mock session and context
@@ -1173,7 +1184,10 @@ async def test_handle_a2a_response_success_with_message(self):
11731184

11741185
assert result == mock_event
11751186
mock_convert.assert_called_once_with(
1176-
mock_a2a_message, self.agent.name, self.mock_context
1187+
mock_a2a_message,
1188+
self.agent.name,
1189+
self.mock_context,
1190+
self.mock_a2a_part_converter,
11771191
)
11781192
# Check that metadata was added
11791193
assert result.custom_metadata is not None
@@ -1211,6 +1225,7 @@ async def test_handle_a2a_response_with_task_completed_and_no_update(self):
12111225
mock_a2a_task,
12121226
self.agent.name,
12131227
self.mock_context,
1228+
self.mock_a2a_part_converter,
12141229
)
12151230
# Check the parts are not updated as Thought
12161231
assert result.content.parts[0].thought is None
@@ -1251,6 +1266,7 @@ async def test_handle_a2a_response_with_task_submitted_and_no_update(self):
12511266
mock_a2a_task,
12521267
self.agent.name,
12531268
self.mock_context,
1269+
self.agent._a2a_part_converter,
12541270
)
12551271
# Check the parts are updated as Thought
12561272
assert result.content.parts[0].thought is True
@@ -1296,6 +1312,7 @@ async def test_handle_a2a_response_with_task_status_update_with_message(self):
12961312
mock_a2a_message,
12971313
self.agent.name,
12981314
self.mock_context,
1315+
self.agent._a2a_part_converter,
12991316
)
13001317
# Check that metadata was added
13011318
assert result.custom_metadata is not None
@@ -1341,6 +1358,7 @@ async def test_handle_a2a_response_with_task_status_working_update_with_message(
13411358
mock_a2a_message,
13421359
self.agent.name,
13431360
self.mock_context,
1361+
self.agent._a2a_part_converter,
13441362
)
13451363
# Check that metadata was added
13461364
assert result.custom_metadata is not None
@@ -1396,7 +1414,10 @@ async def test_handle_a2a_response_with_artifact_update(self):
13961414

13971415
assert result == mock_event
13981416
mock_convert.assert_called_once_with(
1399-
mock_a2a_task, self.agent.name, self.mock_context
1417+
mock_a2a_task,
1418+
self.agent.name,
1419+
self.mock_context,
1420+
self.agent._a2a_part_converter,
14001421
)
14011422
# Check that metadata was added
14021423
assert result.custom_metadata is not None

0 commit comments

Comments
 (0)