You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: Propagate file names during A2A to/from Genai Part conversion
This change updates the part_converter to ensure that the name field in a2a_types.FileWithUri and a2a_types.FileWithBytes is correctly mapped to the display_name field in genai_types.FileData and genai_types.Blob, respectively, during conversions between A2A and Genai Part types. Tests are updated to verify this propagation in both directions. PiperOrigin-RevId: 877507283
This commit is contained in:
committed by
Copybara-Service
parent
90f28deea5
commit
f324fa2d62
@@ -70,7 +70,9 @@ def convert_a2a_part_to_genai_part(
|
||||
if isinstance(part.file, a2a_types.FileWithUri):
|
||||
return genai_types.Part(
|
||||
file_data=genai_types.FileData(
|
||||
file_uri=part.file.uri, mime_type=part.file.mime_type
|
||||
file_uri=part.file.uri,
|
||||
mime_type=part.file.mime_type,
|
||||
display_name=part.file.name,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -79,6 +81,7 @@ def convert_a2a_part_to_genai_part(
|
||||
inline_data=genai_types.Blob(
|
||||
data=base64.b64decode(part.file.bytes),
|
||||
mime_type=part.file.mime_type,
|
||||
display_name=part.file.name,
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -188,6 +191,7 @@ def convert_genai_part_to_a2a_part(
|
||||
file=a2a_types.FileWithUri(
|
||||
uri=part.file_data.file_uri,
|
||||
mime_type=part.file_data.mime_type,
|
||||
name=part.file_data.display_name,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -211,6 +215,7 @@ def convert_genai_part_to_a2a_part(
|
||||
file=a2a_types.FileWithBytes(
|
||||
bytes=base64.b64encode(part.inline_data.data).decode('utf-8'),
|
||||
mime_type=part.inline_data.mime_type,
|
||||
name=part.inline_data.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -55,7 +55,9 @@ class TestConvertA2aPartToGenaiPart:
|
||||
a2a_part = a2a_types.Part(
|
||||
root=a2a_types.FilePart(
|
||||
file=a2a_types.FileWithUri(
|
||||
uri="gs://bucket/file.txt", mime_type="text/plain"
|
||||
uri="gs://bucket/file.txt",
|
||||
mime_type="text/plain",
|
||||
name="my_file.txt",
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -69,6 +71,7 @@ class TestConvertA2aPartToGenaiPart:
|
||||
assert result.file_data is not None
|
||||
assert result.file_data.file_uri == "gs://bucket/file.txt"
|
||||
assert result.file_data.mime_type == "text/plain"
|
||||
assert result.file_data.display_name == "my_file.txt"
|
||||
|
||||
def test_convert_file_part_with_bytes(self):
|
||||
"""Test conversion of A2A FilePart with bytes to GenAI Part."""
|
||||
@@ -80,7 +83,9 @@ class TestConvertA2aPartToGenaiPart:
|
||||
a2a_part = a2a_types.Part(
|
||||
root=a2a_types.FilePart(
|
||||
file=a2a_types.FileWithBytes(
|
||||
bytes=base64_encoded, mime_type="text/plain"
|
||||
bytes=base64_encoded,
|
||||
mime_type="text/plain",
|
||||
name="my_bytes.txt",
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -95,6 +100,7 @@ class TestConvertA2aPartToGenaiPart:
|
||||
# The converter decodes base64 back to original bytes
|
||||
assert result.inline_data.data == test_bytes
|
||||
assert result.inline_data.mime_type == "text/plain"
|
||||
assert result.inline_data.display_name == "my_bytes.txt"
|
||||
|
||||
def test_convert_data_part_function_call(self):
|
||||
"""Test conversion of A2A DataPart with function call metadata."""
|
||||
@@ -296,7 +302,9 @@ class TestConvertGenaiPartToA2aPart:
|
||||
# Arrange
|
||||
genai_part = genai_types.Part(
|
||||
file_data=genai_types.FileData(
|
||||
file_uri="gs://bucket/file.txt", mime_type="text/plain"
|
||||
file_uri="gs://bucket/file.txt",
|
||||
mime_type="text/plain",
|
||||
display_name="my_file.txt",
|
||||
)
|
||||
)
|
||||
|
||||
@@ -310,13 +318,18 @@ class TestConvertGenaiPartToA2aPart:
|
||||
assert isinstance(result.root.file, a2a_types.FileWithUri)
|
||||
assert result.root.file.uri == "gs://bucket/file.txt"
|
||||
assert result.root.file.mime_type == "text/plain"
|
||||
assert result.root.file.name == "my_file.txt"
|
||||
|
||||
def test_convert_inline_data_part(self):
|
||||
"""Test conversion of GenAI inline_data Part to A2A Part."""
|
||||
# Arrange
|
||||
test_bytes = b"test file content"
|
||||
genai_part = genai_types.Part(
|
||||
inline_data=genai_types.Blob(data=test_bytes, mime_type="text/plain")
|
||||
inline_data=genai_types.Blob(
|
||||
data=test_bytes,
|
||||
mime_type="text/plain",
|
||||
display_name="my_bytes.txt",
|
||||
)
|
||||
)
|
||||
|
||||
# Act
|
||||
@@ -332,6 +345,7 @@ class TestConvertGenaiPartToA2aPart:
|
||||
expected_base64 = base64.b64encode(test_bytes).decode("utf-8")
|
||||
assert result.root.file.bytes == expected_base64
|
||||
assert result.root.file.mime_type == "text/plain"
|
||||
assert result.root.file.name == "my_bytes.txt"
|
||||
|
||||
def test_convert_inline_data_part_with_video_metadata(self):
|
||||
"""Test conversion of GenAI inline_data Part with video metadata to A2A Part."""
|
||||
|
||||
Reference in New Issue
Block a user