Skip to content

Commit fad0482

Browse files
fix(compat): keep timestamp and three other fields in v0.3 gRPC conversion (#1277)
## Problem `proto_utils.py` doesn't map `TaskStatus.timestamp`, `AgentCard.icon_url`, `OAuth2SecurityScheme.oauth2_metadata_url` or `AgentSkill.security`, so v0.3 gRPC clients get task statuses with no timestamp. ## Fix Map the four fields in `ToProto` and `FromProto`, the same way `conversions.py` does. ## Tests `test_task_status_timestamp_roundtrip` and `test_agent_card_optional_fields_roundtrip` in `test_proto_utils.py`. Both fail with the source reverted. Fixes #1276 Co-authored-by: mykytanetipa <mykytanetipa@google.com>
1 parent 041c17b commit fad0482

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎src/a2a/compat/v0_3/proto_utils.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,15 @@ def task(cls, task: types.Task) -> a2a_pb2.Task:
211211

212212
@classmethod
213213
def task_status(cls, status: types.TaskStatus) -> a2a_pb2.TaskStatus:
214-
return a2a_pb2.TaskStatus(
214+
proto_status = a2a_pb2.TaskStatus(
215215
state=cls.task_state(status.state),
216216
update=cls.message(status.message),
217217
)
218+
if status.timestamp:
219+
proto_status.timestamp.FromJsonString(
220+
str(status.timestamp).replace('+00:00', 'Z')
221+
)
222+
return proto_status
218223

219224
@classmethod
220225
def task_state(cls, state: types.TaskState) -> a2a_pb2.TaskState:
@@ -405,6 +410,7 @@ def agent_card(
405410
signatures=[cls.agent_card_signature(x) for x in card.signatures]
406411
if card.signatures
407412
else None,
413+
icon_url=card.icon_url,
408414
)
409415

410416
@classmethod
@@ -515,6 +521,7 @@ def security_scheme(
515521
oauth2_security_scheme=a2a_pb2.OAuth2SecurityScheme(
516522
description=scheme.root.description,
517523
flows=cls.oauth2_flows(scheme.root.flows),
524+
oauth2_metadata_url=scheme.root.oauth2_metadata_url,
518525
)
519526
)
520527
if isinstance(scheme.root, types.MutualTLSSecurityScheme):
@@ -577,6 +584,7 @@ def skill(cls, skill: types.AgentSkill) -> a2a_pb2.AgentSkill:
577584
examples=skill.examples,
578585
input_modes=skill.input_modes,
579586
output_modes=skill.output_modes,
587+
security=cls.security(skill.security),
580588
)
581589

582590
@classmethod
@@ -689,6 +697,9 @@ def task_status(cls, status: a2a_pb2.TaskStatus) -> types.TaskStatus:
689697
return types.TaskStatus(
690698
state=cls.task_state(status.state),
691699
message=cls.message(status.update),
700+
timestamp=status.timestamp.ToJsonString()
701+
if status.HasField('timestamp')
702+
else None,
692703
)
693704

694705
@classmethod
@@ -876,6 +887,7 @@ def agent_card(
876887
signatures=[cls.agent_card_signature(x) for x in card.signatures]
877888
if card.signatures
878889
else None,
890+
icon_url=card.icon_url or None,
879891
)
880892

881893
@classmethod
@@ -992,6 +1004,8 @@ def security_scheme(
9921004
root=types.OAuth2SecurityScheme(
9931005
description=scheme.oauth2_security_scheme.description,
9941006
flows=cls.oauth2_flows(scheme.oauth2_security_scheme.flows),
1007+
oauth2_metadata_url=scheme.oauth2_security_scheme.oauth2_metadata_url
1008+
or None,
9951009
)
9961010
)
9971011
if scheme.HasField('mtls_security_scheme'):
@@ -1086,6 +1100,7 @@ def skill(cls, skill: a2a_pb2.AgentSkill) -> types.AgentSkill:
10861100
examples=list(skill.examples),
10871101
input_modes=list(skill.input_modes),
10881102
output_modes=list(skill.output_modes),
1103+
security=cls.security(list(skill.security)),
10891104
)
10901105

10911106
@classmethod

‎tests/compat/v0_3/test_proto_utils.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,43 @@ def test_agent_card_conversion_roundtrip(
640640
),
641641
]
642642

643+
def test_task_status_timestamp_roundtrip(self):
644+
"""TaskStatus.timestamp survives conversion to proto and back."""
645+
status = types.TaskStatus(
646+
state=types.TaskState.working, timestamp='2026-03-15T10:30:00Z'
647+
)
648+
649+
proto_status = proto_utils.ToProto.task_status(status)
650+
assert proto_status.HasField('timestamp')
651+
652+
roundtrip_status = proto_utils.FromProto.task_status(proto_status)
653+
assert roundtrip_status.timestamp == '2026-03-15T10:30:00Z'
654+
655+
def test_agent_card_optional_fields_roundtrip(
656+
self, sample_agent_card: types.AgentCard
657+
):
658+
"""icon_url, oauth2_metadata_url and skill security survive conversion."""
659+
card = sample_agent_card.model_copy(deep=True)
660+
card.icon_url = 'http://localhost/icon.png'
661+
card.skills[0].security = [{'oauth_scheme': ['read']}]
662+
card.security_schemes[
663+
'oauth_scheme'
664+
].root.oauth2_metadata_url = (
665+
'http://localhost/.well-known/oauth-authorization-server'
666+
)
667+
668+
roundtrip_card = proto_utils.FromProto.agent_card(
669+
proto_utils.ToProto.agent_card(card)
670+
)
671+
assert roundtrip_card.icon_url == 'http://localhost/icon.png'
672+
assert roundtrip_card.skills[0].security == [{'oauth_scheme': ['read']}]
673+
assert (
674+
roundtrip_card.security_schemes[
675+
'oauth_scheme'
676+
].root.oauth2_metadata_url
677+
== 'http://localhost/.well-known/oauth-authorization-server'
678+
)
679+
643680
@pytest.mark.parametrize(
644681
'signature_data, expected_data',
645682
[

0 commit comments

Comments
 (0)