fix: respect A2A Message.role in inbound event conversion#5224
fix: respect A2A Message.role in inbound event conversion#5224giulio-leone wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @giulio-leone, thank you for creating this PR! Before we can review your contribution, could you please sign our Contributor License Agreement (CLA)? You can find more information at https://cla.developers.google.com/. Additionally, since this PR is a bug fix, could you please provide logs or a screenshot demonstrating that the fix is working as expected? This will help the reviewers to better understand and verify your changes. Thank you! |
|
Added focused regression coverage for the fix:
Local result: 86 converter tests passed ( This reproduces the original bug path and confirms that user-role messages are no longer misattributed as model output. |
eb26b58 to
877d702
Compare
convert_a2a_message_to_event() hard-coded role='model' on the GenAI Content it produced, ignoring the A2A Message.role field. This caused Role.user messages to be misattributed as model output. Additionally, the task-history fallback in convert_a2a_task_to_event() blindly took history[-1] without checking Message.role, so a trailing user message could be restored as agent output. Changes: - Add a2a_role_to_genai_role() helper in utils.py (Role.agent→'model', Role.user→'user'). - event_converter.py: use the helper instead of hard-coded 'model' in convert_a2a_message_to_event(); filter history fallback to agent-role messages only. - to_adk_event.py: add role parameter to _create_event(); pass mapped role from convert_a2a_message_to_event(). - Regression tests for role restoration and history fallback.
877d702 to
f22ca7d
Compare
Summary
Fixes #5186.
convert_a2a_message_to_event()hard-codedrole='model'on the GenAIContentit produced, ignoring the A2AMessage.rolefield. This causedRole.usermessages to be restored asmodelevents.Additionally, the task-history fallback in
convert_a2a_task_to_event()(inevent_converter.py) blindly tookhistory[-1]without checkingMessage.role, so a trailing user message could be misattributed as agent output.Root Cause
event_converter.py:Content(role="model", ...)was hard-coded in two places insideconvert_a2a_message_to_event().to_adk_event.py:_create_event()hard-codedrole="model"with no way to override.event_converter.py:convert_a2a_task_to_event()fallback path useda2a_task.history[-1]unconditionally.Changes
converters/utils.pya2a_role_to_genai_role()helper (Role.agent→"model",Role.user→"user")converters/event_converter.pyconvert_a2a_message_to_event(); filter history fallback to agent-role messages onlyconverters/to_adk_event.pyroleparam to_create_event(); pass mapped role fromconvert_a2a_message_to_event()test_event_converter.pytest_to_adk.pytest_utils.pya2a_role_to_genai_role()Testing
All 86 converter tests pass (
test_event_converter.py,test_to_adk.py,test_utils.py).