From d9456ca1e6e74c3fe7c81cc6c68c747e07e2a836 Mon Sep 17 00:00:00 2001 From: sokoliva Date: Thu, 20 Nov 2025 16:01:45 +0000 Subject: [PATCH 1/3] fix: add metadata to task in proto_utils.py --- src/a2a/utils/proto_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index d077d62b..cc84274f 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -203,6 +203,7 @@ def task(cls, task: types.Task) -> a2a_pb2.Task: if task.history else None ), + metadata=cls.metadata(task.metadata), ) @classmethod From df36017b9d7c438e6f883bc4e4b0103516bef78b Mon Sep 17 00:00:00 2001 From: sokoliva Date: Thu, 20 Nov 2025 21:46:25 +0000 Subject: [PATCH 2/3] add `metadata` to from proto to types task conversion. Add `test_task_conversion_roundtrip`. --- src/a2a/utils/proto_utils.py | 1 + tests/utils/test_proto_utils.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index cc84274f..8bf01eea 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -661,6 +661,7 @@ def task(cls, task: a2a_pb2.Task) -> types.Task: status=cls.task_status(task.status), artifacts=[cls.artifact(a) for a in task.artifacts], history=[cls.message(h) for h in task.history], + metadata=cls.metadata(task.metadata), ) @classmethod diff --git a/tests/utils/test_proto_utils.py b/tests/utils/test_proto_utils.py index da54f833..a113683e 100644 --- a/tests/utils/test_proto_utils.py +++ b/tests/utils/test_proto_utils.py @@ -31,7 +31,7 @@ def sample_message() -> types.Message: ), types.Part(root=types.DataPart(data={'key': 'value'})), ], - metadata={'source': 'test'}, + metadata={'source': 'test', 'priority': 5}, ) @@ -52,6 +52,7 @@ def sample_task(sample_message: types.Message) -> types.Task: ], ) ], + metadata={'source': 'test'}, ) @@ -508,3 +509,30 @@ def test_large_integer_roundtrip_with_utilities(self): assert final_result['nested']['another_large'] == 12345678901234567890 assert isinstance(final_result['nested']['another_large'], int) assert final_result['nested']['normal'] == 'text' + + def test_task_conversion_roundtrip( + self, sample_task: types.Task, sample_message: types.Message + ): + """Test conversion of Task to proto and back.""" + proto_task = proto_utils.ToProto.task(sample_task) + assert isinstance(proto_task, a2a_pb2.Task) + + roundtrip_task = proto_utils.FromProto.task(proto_task) + assert roundtrip_task.id == 'task-1' + assert roundtrip_task.context_id == 'ctx-1' + assert roundtrip_task.status == types.TaskStatus( + state=types.TaskState.working, message=sample_message + ) + assert roundtrip_task.history == [sample_message] + assert roundtrip_task.artifacts == [ + types.Artifact( + artifact_id='art-1', + description='', + metadata={}, + name='', + parts=[ + types.Part(root=types.TextPart(text='Artifact content')) + ], + ) + ] + assert roundtrip_task.metadata == {'source': 'test'} From c4d0c7c520223f1e04bb8cf0552ac12a84a62d4e Mon Sep 17 00:00:00 2001 From: sokoliva Date: Fri, 21 Nov 2025 09:08:42 +0000 Subject: [PATCH 3/3] refractor: remove accidentally added metadata entry in sample_message to improve readability. --- tests/utils/test_proto_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/test_proto_utils.py b/tests/utils/test_proto_utils.py index a113683e..33be1f3f 100644 --- a/tests/utils/test_proto_utils.py +++ b/tests/utils/test_proto_utils.py @@ -31,7 +31,7 @@ def sample_message() -> types.Message: ), types.Part(root=types.DataPart(data={'key': 'value'})), ], - metadata={'source': 'test', 'priority': 5}, + metadata={'source': 'test'}, )