-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
In case of remote A2A agent, when constructing A2A message parts from session events the message parts order is backwords (the most recent message is the first item in the array).
To Reproduce
Create 2 remote A2A agent and configure them as subagents in another llm_agent.
And make subsequent calls that should be routed to different sub agent, you should see that the parts extracted from session events are added in reverse order.
Expected behavior
Expected the remote A2A agent to get the content generated by other agents in the currect order, instead the most recent message is the first item in the message parts array.
Note that the "For context:" text is also out of order (comes after the part that it's describing)
Screenshots
{
"id": "7338277f-eba0-4dc4-aea2-cca926065a26",
"jsonrpc": "2.0",
"method": "message/stream",
"params": {
"configuration": {
"acceptedOutputModes": [],
"blocking": true
},
"message": {
"kind": "message",
"messageId": "aad0ac51-ba5a-4378-9c9e-e38f21af7a43",
"parts": [
{
"kind": "text",
"text": "what is my org id?"
},
{
"kind": "text",
"text": "[supervisor_agent] called tool `transfer_to_agent` with parameters: {'agent_name': 'va_agent'}"
},
{
"kind": "text",
"text": "For context:"
},
{
"kind": "text",
"text": "[supervisor_agent] `transfer_to_agent` tool returned result: {'result': None}"
},
{
"kind": "text",
"text": "For context:"
}
],
"role": "user"
}
}
}
Desktop (please complete the following information):
- OS: [e.g. macOS, Linux, Windows]: Linux
- Python version(python -V): 3.12.11
- ADK version(pip show google-adk): 1.16.0
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-pro
Additional context
The llm_agent do this:
adk-python/src/google/adk/flows/llm_flows/contents.py
Lines 313 to 316 in 2f4f561
| # Filter out events that are annulled by a rewind. | |
| # By iterating backward, when a rewind event is found, we skip all events | |
| # from that point back to the `rewind_before_invocation_id`, thus removing | |
| # them from the history used for the LLM request. |
Since the events were collected while iterating backward, the
rewind_filtered_events list is in reverse chronological order.Hence the
.reverse() call is required to flip it back to the original, correct order.But there's no reason to do that
.reverse() call in the RemoteA2aAgent