You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Object of type Role is not JSON serializable because of Enum typing of Message.Role instead of StrEnum #107
will fail as enum cannot be serialized (throws: TypeError: Object of type Role is not JSON serializable)
By changing a2a.types
fromenumimportEnumclassRole(Enum):
""" Message sender's role """agent='agent'user='user'
into
fromenumimportStrEnumclassRole(StrEnum):
""" Message sender's role """agent='agent'user='user'
the role can be serialized to JSON with model_dump() as Pydantic can treat it as a string. As i cannot create branches I can’t create a PR. Would strongly suggest this approach for other string based enums as well.
Workaround would be to create an anti-corruption serialization function for MessageSendParams serialization
Relevant log output
TypeError: Object of type Role is not JSON serializable
changed the title [-][Bug]: Enum for Message Role instead of StrEnum[/-][+][Bug]: Object of type Role is not JSON serializable because of Enum typing of Message.Role instead of StrEnum[/+]on May 26, 2025
Activity
[-][Bug]: Enum for Message Role instead of StrEnum[/-][+][Bug]: Object of type Role is not JSON serializable because of Enum typing of Message.Role instead of StrEnum[/+]kthota-g commentedon May 28, 2025
This is being addressed part of #134
Until the change is available in the SDK, using
params.model_dump(mode='json')will serialize to JSON types.