Commit fe08a9f
fix: map A2A Message.role to correct GenAI content role
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: 9339268121 parent 796964a commit fe08a9f
2 files changed
Lines changed: 51 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
187 | 188 | | |
188 | 189 | | |
189 | 190 | | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
| |||
209 | 211 | | |
210 | 212 | | |
211 | 213 | | |
212 | | - | |
| 214 | + | |
213 | 215 | | |
214 | 216 | | |
215 | 217 | | |
| |||
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
224 | 233 | | |
225 | 234 | | |
226 | 235 | | |
| |||
468 | 477 | | |
469 | 478 | | |
470 | 479 | | |
| 480 | + | |
471 | 481 | | |
472 | 482 | | |
473 | 483 | | |
474 | 484 | | |
475 | 485 | | |
| 486 | + | |
476 | 487 | | |
477 | 488 | | |
478 | 489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
643 | 644 | | |
644 | 645 | | |
645 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
0 commit comments