You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
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
This commit is contained in:
committed by
Copybara-Service
parent
636f68fbee
commit
e59929e11a
@@ -61,7 +61,10 @@ def convert_a2a_part_to_genai_part(
|
||||
"""Convert an A2A Part to a Google GenAI Part."""
|
||||
part = a2a_part.root
|
||||
if isinstance(part, a2a_types.TextPart):
|
||||
return genai_types.Part(text=part.text)
|
||||
thought = None
|
||||
if part.metadata:
|
||||
thought = part.metadata.get(_get_adk_metadata_key('thought'))
|
||||
return genai_types.Part(text=part.text, thought=thought)
|
||||
|
||||
if isinstance(part, a2a_types.FilePart):
|
||||
if isinstance(part.file, a2a_types.FileWithUri):
|
||||
|
||||
@@ -289,7 +289,7 @@ class TestConvertGenaiPartToA2aPart:
|
||||
assert isinstance(result.root, a2a_types.TextPart)
|
||||
assert result.root.text == "Hello, world!"
|
||||
assert result.root.metadata is not None
|
||||
assert result.root.metadata[_get_adk_metadata_key("thought")] == True
|
||||
assert result.root.metadata[_get_adk_metadata_key("thought")]
|
||||
|
||||
def test_convert_file_data_part(self):
|
||||
"""Test conversion of GenAI file_data Part to A2A Part."""
|
||||
@@ -516,6 +516,22 @@ class TestRoundTripConversions:
|
||||
assert isinstance(result_a2a_part.root, a2a_types.TextPart)
|
||||
assert result_a2a_part.root.text == original_text
|
||||
|
||||
def test_text_part_with_thought_round_trip(self):
|
||||
"""Test round-trip conversion for text parts with thought."""
|
||||
# Arrange
|
||||
original_text = "Thinking..."
|
||||
genai_part = genai_types.Part(text=original_text, thought=True)
|
||||
|
||||
# Act
|
||||
a2a_part = convert_genai_part_to_a2a_part(genai_part)
|
||||
result_genai_part = convert_a2a_part_to_genai_part(a2a_part)
|
||||
|
||||
# Assert
|
||||
assert result_genai_part is not None
|
||||
assert isinstance(result_genai_part, genai_types.Part)
|
||||
assert result_genai_part.text == original_text
|
||||
assert result_genai_part.thought
|
||||
|
||||
def test_file_uri_round_trip(self):
|
||||
"""Test round-trip conversion for file parts with URI."""
|
||||
# Arrange
|
||||
|
||||
Reference in New Issue
Block a user