Skip to content

Commit fc31d03

Browse files
authored
fix: Ensure metadata propagation for Task ToProto and FromProto conversion (#557)
The `metadata` dictionary is now correctly propagated in both the `ToProto` (types.Task to a2a_pb2.Task) and `FromProto` (a2a_pb2.Task to types.Task) conversion utilities. Release-As:0.3.16 Fixes #541 🦕
1 parent fdb4731 commit fc31d03

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/a2a/utils/proto_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def task(cls, task: types.Task) -> a2a_pb2.Task:
203203
if task.history
204204
else None
205205
),
206+
metadata=cls.metadata(task.metadata),
206207
)
207208

208209
@classmethod
@@ -660,6 +661,7 @@ def task(cls, task: a2a_pb2.Task) -> types.Task:
660661
status=cls.task_status(task.status),
661662
artifacts=[cls.artifact(a) for a in task.artifacts],
662663
history=[cls.message(h) for h in task.history],
664+
metadata=cls.metadata(task.metadata),
663665
)
664666

665667
@classmethod

tests/utils/test_proto_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def sample_task(sample_message: types.Message) -> types.Task:
5252
],
5353
)
5454
],
55+
metadata={'source': 'test'},
5556
)
5657

5758

@@ -508,3 +509,30 @@ def test_large_integer_roundtrip_with_utilities(self):
508509
assert final_result['nested']['another_large'] == 12345678901234567890
509510
assert isinstance(final_result['nested']['another_large'], int)
510511
assert final_result['nested']['normal'] == 'text'
512+
513+
def test_task_conversion_roundtrip(
514+
self, sample_task: types.Task, sample_message: types.Message
515+
):
516+
"""Test conversion of Task to proto and back."""
517+
proto_task = proto_utils.ToProto.task(sample_task)
518+
assert isinstance(proto_task, a2a_pb2.Task)
519+
520+
roundtrip_task = proto_utils.FromProto.task(proto_task)
521+
assert roundtrip_task.id == 'task-1'
522+
assert roundtrip_task.context_id == 'ctx-1'
523+
assert roundtrip_task.status == types.TaskStatus(
524+
state=types.TaskState.working, message=sample_message
525+
)
526+
assert roundtrip_task.history == [sample_message]
527+
assert roundtrip_task.artifacts == [
528+
types.Artifact(
529+
artifact_id='art-1',
530+
description='',
531+
metadata={},
532+
name='',
533+
parts=[
534+
types.Part(root=types.TextPart(text='Artifact content'))
535+
],
536+
)
537+
]
538+
assert roundtrip_task.metadata == {'source': 'test'}

0 commit comments

Comments
 (0)