Skip to content

Commit bd7cd00

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 929729687
1 parent ec93f50 commit bd7cd00

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashMap;
4444
import java.util.List;
4545
import java.util.Map;
46+
import java.util.Objects;
4647
import java.util.Optional;
4748
import org.slf4j.Logger;
4849
import org.slf4j.LoggerFactory;
@@ -80,7 +81,13 @@ public static com.google.genai.types.Part toGenaiPart(io.a2a.spec.Part<?> a2aPar
8081
}
8182

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

8693
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)