Skip to content

A2A inbound message conversion ignores Message.role, always maps to "model" #5186

Closed

Description

@YizukiAme

Bug Description

convert_a2a_message_to_event() in to_adk_event.py 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.

The task history fallback (a2a_task.history[-1]) also does not check Message.role, so a trailing user message can be treated as agent output.

Steps to Reproduce

from a2a.types import Message, Part, TextPart, Role

user_msg = Message(
    role=Role.user,
    parts=[Part(root=TextPart(text="Hello"))],
    metadata={}
)
event = convert_a2a_message_to_event(user_msg, author="user")
# event author is always "model" — should reflect "user"

Expected Behavior

  • A2A Role.user should map to an ADK event with role="user"
  • History fallback should only use agent-role messages to avoid misattribution

Affected Files

  • src/google/adk/a2a/converters/to_adk_event.py

Activity

  1. enjoykumawat commented on Apr 7, 2026

    @enjoykumawat
    Contributor

    I'd like to work on this. The fix should map Message.role to the correct ADK event author/role instead of hard-coding "model" in convert_a2a_message_to_event(). Will submit a PR shortly.

  2. added a commit that references this issue on Apr 7, 2026
    f0ec673
  3. anowardear062-svg commented on Apr 7, 2026

    @anowardear062-svg

    Thanks

  4. added theissue type on Apr 8, 2026
  5. added
    core[Component] This issue is related to the core interface and implementation
    on Apr 8, 2026
  6. added a commit that references this issue on Apr 9, 2026
    ec8a49e
  7. surajksharma07 commented on Apr 9, 2026

    @surajksharma07
    Collaborator

    @YizukiAme _create_event() in to_adk_event.py hardcodes role="model" and never reads a2a_message.role, which is what's causing the misattribution.

    As a quick workaround, try wrapping convert_a2a_message_to_event() and fixing the role post-call via event.model_copy(update={"content": event.content.model_copy(update={"role": "user" if msg.role == Role.user else "model"})}).

    It's also worth filtering history[-1] to agent-role only to avoid the second misattribution while you're in there.

    Could you give that a try and let us know if it clears both issues on your end?
    PR #5224 is already heading in this direction, so your confirmation there before it moves forward would be really helpful!

  8. YizukiAme commented on Apr 9, 2026

    @YizukiAme
    Author

    Thanks @surajksharma07! I reviewed the diff in PR #5224 and the fix looks correct for both issues:

    1. Role hardcoding: a2a_role_to_genai_role() correctly maps Role.user → "user" in both event_converter.py and to_adk_event.py.
    2. History fallback: history[-1] is now filtered to Role.agent only, preventing trailing user messages from being misattributed.

    (I originally found this via code audit rather than a live A2A setup, so my verification is code-level. But the root cause was a hardcoded string, and the fix + regression tests clearly address it.)

    LGTM from the reporter side~ 👍

  9. surajksharma07 commented on Apr 10, 2026

    @surajksharma07
    Collaborator

    Thanks for the thorough review @YizukiAme — a code-level LGTM is completely valid here given the root cause was a straightforward hardcode with no ambiguity.

    We currently have two PRs open targeting the same fix (#5198 by @enjoykumawat and #5224 by @giulio-leone), so the team will review both and consolidate before merging.

    We'll get this closed out once one lands — really appreciate you circling back so quickly!

  10. surajksharma07 commented on Apr 10, 2026

    @surajksharma07
    Collaborator

    @Jacksunwei Please have a look into it once.

  11. added a commit that references this issue on Jun 17, 2026
    fe08a9f
  12. added a commit that references this issue on Jul 22, 2026
    968845f
  13. added 2 commits that reference this issue on Aug 11, 2026
    9f5c4e3
    b19e5a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationneeds review[Status] The PR/issue is awaiting review from the maintainer

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions