Skip to content

Commit e59929e

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Propagate thought from A2A TextPart metadata to GenAI Part
When converting an A2A TextPart to a GenAI Part, extract the 'thought' field from the TextPart's metadata and include it in the GenAI Part. PiperOrigin-RevId: 875129430
1 parent 636f68f commit e59929e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/google/adk/a2a/converters/part_converter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def convert_a2a_part_to_genai_part(
6161
"""Convert an A2A Part to a Google GenAI Part."""
6262
part = a2a_part.root
6363
if isinstance(part, a2a_types.TextPart):
64-
return genai_types.Part(text=part.text)
64+
thought = None
65+
if part.metadata:
66+
thought = part.metadata.get(_get_adk_metadata_key('thought'))
67+
return genai_types.Part(text=part.text, thought=thought)
6568

6669
if isinstance(part, a2a_types.FilePart):
6770
if isinstance(part.file, a2a_types.FileWithUri):

tests/unittests/a2a/converters/test_part_converter.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_convert_text_part_with_thought(self):
289289
assert isinstance(result.root, a2a_types.TextPart)
290290
assert result.root.text == "Hello, world!"
291291
assert result.root.metadata is not None
292-
assert result.root.metadata[_get_adk_metadata_key("thought")] == True
292+
assert result.root.metadata[_get_adk_metadata_key("thought")]
293293

294294
def test_convert_file_data_part(self):
295295
"""Test conversion of GenAI file_data Part to A2A Part."""
@@ -516,6 +516,22 @@ def test_text_part_round_trip(self):
516516
assert isinstance(result_a2a_part.root, a2a_types.TextPart)
517517
assert result_a2a_part.root.text == original_text
518518

519+
def test_text_part_with_thought_round_trip(self):
520+
"""Test round-trip conversion for text parts with thought."""
521+
# Arrange
522+
original_text = "Thinking..."
523+
genai_part = genai_types.Part(text=original_text, thought=True)
524+
525+
# Act
526+
a2a_part = convert_genai_part_to_a2a_part(genai_part)
527+
result_genai_part = convert_a2a_part_to_genai_part(a2a_part)
528+
529+
# Assert
530+
assert result_genai_part is not None
531+
assert isinstance(result_genai_part, genai_types.Part)
532+
assert result_genai_part.text == original_text
533+
assert result_genai_part.thought
534+
519535
def test_file_uri_round_trip(self):
520536
"""Test round-trip conversion for file parts with URI."""
521537
# Arrange

0 commit comments

Comments
 (0)