Skip to content

Commit 0f0ad60

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 929073031
1 parent ec93f50 commit 0f0ad60

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

a2a/src/main/java/com/google/adk/a2a/converters/PartConverter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public static com.google.genai.types.Part toGenaiPart(io.a2a.spec.Part<?> a2aPar
8080
}
8181

8282
if (a2aPart instanceof TextPart textPart) {
83-
return com.google.genai.types.Part.builder().text(textPart.getText()).build();
83+
com.google.genai.types.Part.Builder partBuilder =
84+
com.google.genai.types.Part.builder().text(textPart.getText());
85+
if (textPart.getMetadata() != null
86+
&& Boolean.TRUE.equals(textPart.getMetadata().get("thought"))) {
87+
partBuilder.thought(true);
88+
}
89+
return partBuilder.build();
8490
}
8591

8692
if (a2aPart instanceof FilePart filePart) {

a2a/src/test/java/com/google/adk/a2a/converters/PartConverterTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,46 @@ public void toGenaiPart_withTextPart_returnsGenaiTextPart() {
4343
assertThat(result.text()).hasValue("Hello");
4444
}
4545

46+
@Test
47+
public void toGenaiPart_withTextPartThought_returnsGenaiTextPartWithThought() {
48+
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", true));
49+
50+
Part result = PartConverter.toGenaiPart(textPart);
51+
52+
assertThat(result.text()).hasValue("Thinking process");
53+
assertThat(result.thought()).hasValue(true);
54+
}
55+
56+
@Test
57+
public void toGenaiPart_withTextPartMetadataWithoutThought_returnsGenaiTextPartWithoutThought() {
58+
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("otherKey", "value"));
59+
60+
Part result = PartConverter.toGenaiPart(textPart);
61+
62+
assertThat(result.text()).hasValue("Thinking process");
63+
assertThat(result.thought()).isEmpty();
64+
}
65+
66+
@Test
67+
public void toGenaiPart_withTextPartThoughtFalse_returnsGenaiTextPartWithoutThought() {
68+
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", false));
69+
70+
Part result = PartConverter.toGenaiPart(textPart);
71+
72+
assertThat(result.text()).hasValue("Thinking process");
73+
assertThat(result.thought()).isEmpty();
74+
}
75+
76+
@Test
77+
public void toGenaiPart_withTextPartNonBooleanThought_returnsGenaiTextPartWithoutThought() {
78+
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", "true"));
79+
80+
Part result = PartConverter.toGenaiPart(textPart);
81+
82+
assertThat(result.text()).hasValue("Thinking process");
83+
assertThat(result.thought()).isEmpty();
84+
}
85+
4686
@Test
4787
public void toGenaiPart_withFilePartUri_returnsGenaiFilePart() {
4888
FilePart filePart = new FilePart(new FileWithUri("text/plain", "file.txt", "http://file.txt"));

0 commit comments

Comments
 (0)