Skip to content

Commit df36017

Browse files
committed
add metadata to from proto to types task conversion. Add test_task_conversion_roundtrip.
1 parent d9456ca commit df36017

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/a2a/utils/proto_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ def task(cls, task: a2a_pb2.Task) -> types.Task:
661661
status=cls.task_status(task.status),
662662
artifacts=[cls.artifact(a) for a in task.artifacts],
663663
history=[cls.message(h) for h in task.history],
664+
metadata=cls.metadata(task.metadata),
664665
)
665666

666667
@classmethod

tests/utils/test_proto_utils.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def sample_message() -> types.Message:
3131
),
3232
types.Part(root=types.DataPart(data={'key': 'value'})),
3333
],
34-
metadata={'source': 'test'},
34+
metadata={'source': 'test', 'priority': 5},
3535
)
3636

3737

@@ -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)