Skip to content

Commit 06529d2

Browse files
google-genai-botcopybara-github
authored andcommitted
Fix a bug in SessionUtils that filtered out all previous events in chats for Vertex stored sessions.
PiperOrigin-RevId: 769565534
1 parent c9fcba9 commit 06529d2

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

core/src/main/java/com/google/adk/sessions/SessionUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static Content encodeContent(Content content) {
5252
encodedParts.add(part);
5353
}
5454
}
55-
return Content.builder().parts(encodedParts).build();
55+
return toContent(encodedParts, content.role());
5656
}
5757

5858
public static Content decodeContent(Content content) {
@@ -77,6 +77,12 @@ public static Content decodeContent(Content content) {
7777
decodedParts.add(part);
7878
}
7979
}
80-
return Content.builder().parts(decodedParts).build();
80+
return toContent(decodedParts, content.role());
81+
}
82+
83+
private static Content toContent(List<Part> parts, Optional<String> role) {
84+
Content.Builder contentBuilder = Content.builder().parts(parts);
85+
role.ifPresent(contentBuilder::role);
86+
return contentBuilder.build();
8187
}
8288
}

0 commit comments

Comments
 (0)