Skip to content

Commit 8e8f7ef

Browse files
committed
Fix: Correct message part ordering in A2A history
The previous logic iterated through session events in reverse and then reversed the resulting list of parts. This caused incorrect ordering for multi-part messages generated by `_present_other_agent_message`. Specifically, introductory text like "For context:" was appearing after the content it was meant to introduce. This change simplifies the implementation by removing both reversals. It now processes events in chronological order, ensuring all message parts are appended in the correct sequence. Signed-off-by: Eran Cohen <[email protected]>
1 parent 955632c commit 8e8f7ef

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/google/adk/agents/remote_a2a_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _construct_message_parts_from_session(
356356
"""
357357
message_parts: list[A2APart] = []
358358
context_id = None
359-
for event in reversed(ctx.session.events):
359+
for event in ctx.session.events:
360360
if _is_other_agent_reply(self.name, event):
361361
event = _present_other_agent_message(event)
362362
elif event.author == self.name:
@@ -378,7 +378,7 @@ def _construct_message_parts_from_session(
378378
else:
379379
logger.warning("Failed to convert part to A2A format: %s", part)
380380

381-
return message_parts[::-1], context_id
381+
return message_parts, context_id
382382

383383
async def _handle_a2a_response(
384384
self, a2a_response: A2AClientEvent | A2AMessage, ctx: InvocationContext

0 commit comments

Comments
 (0)