fix: map A2A Message.role to correct GenAI content role#5198
Open
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
Open
fix: map A2A Message.role to correct GenAI content role#5198enjoykumawat wants to merge 2 commits intogoogle:mainfrom
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
Conversation
convert_a2a_message_to_event() hard-coded role="model" for all resulting ADK events regardless of the original A2A Message.role. User messages (Role.user) were incorrectly restored as model events. Add _a2a_role_to_content_role() helper that maps A2A Role.user to "user" and Role.agent to "model", and pass the mapped role through _create_event() via a new content_role parameter. Fixes google#5186
b9190e2 to
bec6717
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5186 —
convert_a2a_message_to_event()hard-codesrole="model"for all resulting ADK events, regardless of the original A2AMessage.role. User messages (Role.user) are incorrectly restored as model events.Root cause:
_create_event()always createsgenai_types.Content(role="model", ...)without considering the source message's role.Fix:
_a2a_role_to_content_role()helper that mapsA2ARole.user→"user"andA2ARole.agent→"model"content_roleparameter to_create_event()(defaults to"model"for backward compatibility)convert_a2a_message_to_event()through to_create_event()Changes
src/google/adk/a2a/converters/to_adk_event.py: ImportRole, add role mapping helper, threadcontent_rolethrough_create_event()tests/unittests/a2a/converters/test_to_adk.py: Add 2 tests verifying user→"user" and agent→"model" role mappingTest plan
test_to_adk.pytests pass (14 existing + 2 new)Role.user→content.role == "user",Role.agent→content.role == "model"