Skip to content

Commit 9478705

Browse files
fix(helpers): convert data parts to Python objects and use public import
1 parent 1b1c8ca commit 9478705

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/a2a/helpers/proto_helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any
77

88
from google.protobuf import struct_pb2
9-
from google.protobuf.json_format import ParseDict
9+
from google.protobuf.json_format import MessageToDict, ParseDict
1010

1111
from a2a.types.a2a_pb2 import (
1212
Artifact,
@@ -404,16 +404,16 @@ def get_text_parts(parts: Sequence[Part]) -> list[str]:
404404
def get_data_parts(parts: Sequence[Part]) -> list[Any]:
405405
"""Extracts structured data from all data Parts.
406406
407-
Each returned element is the Python object obtained from the
408-
``google.protobuf.Value`` stored in the Part.
407+
Each returned element is the Python object obtained by converting
408+
the ``google.protobuf.Value`` back via ``MessageToDict``.
409409
410410
Args:
411411
parts: A sequence of ``Part`` objects.
412412
413413
Returns:
414-
A list of deserialized data values from any data Parts found.
414+
A list of deserialized Python objects from any data Parts found.
415415
"""
416-
return [part.data for part in parts if part.HasField('data')]
416+
return [MessageToDict(part.data) for part in parts if part.HasField('data')]
417417

418418

419419
def get_raw_parts(parts: Sequence[Part]) -> list[bytes]:

tests/helpers/test_proto_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from a2a.helpers.proto_helpers import (
5+
from a2a.helpers import (
66
get_artifact_text,
77
get_data_parts,
88
get_message_text,
@@ -462,8 +462,8 @@ def test_get_data_parts() -> None:
462462
]
463463
result = get_data_parts(parts)
464464
assert len(result) == 2
465-
assert result[0].struct_value.fields['key'].string_value == 'value'
466-
assert result[1].list_value.values[0].number_value == 1
465+
assert result[0] == {'key': 'value'}
466+
assert result[1] == [1, 2]
467467

468468

469469
def test_get_data_parts_empty() -> None:

0 commit comments

Comments
 (0)