Repository navigation
fix: map A2A Message.role to correct GenAI content role - #5198
Closed
enjoykumawat wants to merge 3 commits into
Closed
enjoykumawat wants to merge 3 commits into
enjoykumawat wants to merge 3 commits into
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
enjoykumawat
force-pushed
the
fix/a2a-message-role-mapping
branch
from
April 9, 2026 07:40
b9190e2 to
bec6717
Compare
Collaborator
|
Hi @enjoykumawat , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
Collaborator
|
Hi @DeanChensj , can you please review this. |
copybara-service Bot
pushed a commit
that referenced
this pull request
Jun 17, 2026
Merge #5198 ## Summary Fixes #5186 — `convert_a2a_message_to_event()` hard-codes `role="model"` for all resulting ADK events, regardless of the original A2A `Message.role`. User messages (`Role.user`) are incorrectly restored as model events. **Root cause:** `_create_event()` always creates `genai_types.Content(role="model", ...)` without considering the source message's role. **Fix:** - Add `_a2a_role_to_content_role()` helper that maps `A2ARole.user` → `"user"` and `A2ARole.agent` → `"model"` - Add `content_role` parameter to `_create_event()` (defaults to `"model"` for backward compatibility) - Pass the mapped role from `convert_a2a_message_to_event()` through to `_create_event()` ## Changes - `src/google/adk/a2a/converters/to_adk_event.py`: Import `Role`, add role mapping helper, thread `content_role` through `_create_event()` - `tests/unittests/a2a/converters/test_to_adk.py`: Add 2 tests verifying user→"user" and agent→"model" role mapping ## Test plan - [x] All 16 `test_to_adk.py` tests pass (14 existing + 2 new) - [x] New tests verify: `Role.user` → `content.role == "user"`, `Role.agent` → `content.role == "model"` - [x] No regressions in existing converter tests Co-authored-by: Haran Rajkumar <haranrk@google.com> COPYBARA_INTEGRATE_REVIEW=#5198 from enjoykumawat:fix/a2a-message-role-mapping da6826d PiperOrigin-RevId: 933926812
Collaborator
|
Thank you @enjoykumawat for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit fe08a9f. Closing this PR as the changes are now in the main branch. |
FrigaZzz
pushed a commit
to FrigaZzz/adk-python
that referenced
this pull request
Aug 11, 2026
Merge google#5198 ## Summary Fixes google#5186 — `convert_a2a_message_to_event()` hard-codes `role="model"` for all resulting ADK events, regardless of the original A2A `Message.role`. User messages (`Role.user`) are incorrectly restored as model events. **Root cause:** `_create_event()` always creates `genai_types.Content(role="model", ...)` without considering the source message's role. **Fix:** - Add `_a2a_role_to_content_role()` helper that maps `A2ARole.user` → `"user"` and `A2ARole.agent` → `"model"` - Add `content_role` parameter to `_create_event()` (defaults to `"model"` for backward compatibility) - Pass the mapped role from `convert_a2a_message_to_event()` through to `_create_event()` ## Changes - `src/google/adk/a2a/converters/to_adk_event.py`: Import `Role`, add role mapping helper, thread `content_role` through `_create_event()` - `tests/unittests/a2a/converters/test_to_adk.py`: Add 2 tests verifying user→"user" and agent→"model" role mapping ## Test plan - [x] All 16 `test_to_adk.py` tests pass (14 existing + 2 new) - [x] New tests verify: `Role.user` → `content.role == "user"`, `Role.agent` → `content.role == "model"` - [x] No regressions in existing converter tests Co-authored-by: Haran Rajkumar <haranrk@google.com> COPYBARA_INTEGRATE_REVIEW=google#5198 from enjoykumawat:fix/a2a-message-role-mapping da6826d PiperOrigin-RevId: 933926812
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"