Skip to content

Commit f431881

Browse files
authored
Merge branch 'main' into ssu/boolean-confirmation-hitl
2 parents 32dc8e5 + ea12505 commit f431881

3 files changed

Lines changed: 45 additions & 26 deletions

File tree

core/src/main/java/com/google/adk/flows/llmflows/Contents.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ private List<Event> processCompactionEvent(List<Event> events) {
209209
List<Event> result = new ArrayList<>();
210210
ListIterator<Event> iter = events.listIterator(events.size());
211211
Long lastCompactionStartTime = null;
212+
Long lastCompactionEndTime = null;
212213

213214
while (iter.hasPrevious()) {
214215
Event event = iter.previous();
215216
EventCompaction compaction = event.actions().compaction().orElse(null);
216217
if (compaction == null) {
217-
if (lastCompactionStartTime == null || event.timestamp() < lastCompactionStartTime) {
218+
if (lastCompactionStartTime == null
219+
|| event.timestamp() < lastCompactionStartTime
220+
|| (lastCompactionEndTime != null && event.timestamp() > lastCompactionEndTime)) {
218221
result.add(event);
219222
}
220223
continue;
@@ -233,6 +236,10 @@ private List<Event> processCompactionEvent(List<Event> events) {
233236
lastCompactionStartTime == null
234237
? compaction.startTimestamp()
235238
: Long.min(lastCompactionStartTime, compaction.startTimestamp());
239+
lastCompactionEndTime =
240+
lastCompactionEndTime == null
241+
? compaction.endTimestamp()
242+
: Long.max(lastCompactionEndTime, compaction.endTimestamp());
236243
}
237244
return Lists.reverse(result);
238245
}

core/src/test/java/com/google/adk/flows/llmflows/ContentsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,22 @@ public void processRequest_multipleCompactions() {
561561
.containsExactly("Summary 1-4", "content 5", "Summary 6-9", "content 10");
562562
}
563563

564+
@Test
565+
public void processRequest_compactionWithUncompactedEventsBetween() {
566+
ImmutableList<Event> events =
567+
ImmutableList.of(
568+
createUserEvent("e1", "content 1", "inv1", 1),
569+
createUserEvent("e2", "content 2", "inv2", 2),
570+
createUserEvent("e3", "content 3", "inv3", 3),
571+
createCompactedEvent(1, 2, "Summary 1-2"));
572+
573+
List<Content> contents = runContentsProcessor(events);
574+
assertThat(contents)
575+
.comparingElementsUsing(
576+
transforming((Content c) -> c.parts().get().get(0).text().get(), "content text"))
577+
.containsExactly("content 3", "Summary 1-2");
578+
}
579+
564580
private static Event createUserEvent(String id, String text) {
565581
return Event.builder()
566582
.id(id)

core/src/test/java/com/google/adk/flows/llmflows/RequestConfirmationLlmRequestProcessorTest.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,35 @@
3636
import com.google.genai.types.FunctionCall;
3737
import com.google.genai.types.FunctionResponse;
3838
import com.google.genai.types.Part;
39+
import java.util.Optional;
3940
import org.junit.Test;
4041
import org.junit.runner.RunWith;
4142
import org.junit.runners.JUnit4;
4243

4344
@RunWith(JUnit4.class)
4445
public class RequestConfirmationLlmRequestProcessorTest {
45-
private static final String ORIGINAL_FUNCTION_CALL_ID = "fc0";
46-
private static final String REQUEST_CONFIRMATION_FUNCTION_CALL_ID = "fc1";
4746
private static final String ECHO_TOOL_NAME = "echo_tool";
47+
private static final String ORIGINAL_FUNCTION_CALL_ID = "original_fc_id";
48+
private static final ImmutableMap<String, Object> ORIGINAL_FUNCTION_CALL_ARGS =
49+
ImmutableMap.of("say", "hello");
50+
private static final String FUNCTION_CALL_ID = "fc_id";
51+
private static final ImmutableMap<String, Object> ARGS =
52+
ImmutableMap.of(
53+
"originalFunctionCall",
54+
ImmutableMap.of( // original function call as a map
55+
"id",
56+
Optional.of("original_fc_id"),
57+
"name",
58+
Optional.of(ECHO_TOOL_NAME),
59+
"args",
60+
Optional.of(ORIGINAL_FUNCTION_CALL_ARGS)));
61+
private static final FunctionCall FUNCTION_CALL =
62+
FunctionCall.builder().id(FUNCTION_CALL_ID).name(ECHO_TOOL_NAME).args(ARGS).build();
4863

4964
private static final Event REQUEST_CONFIRMATION_EVENT =
5065
Event.builder()
5166
.author("model")
52-
.content(
53-
Content.fromParts(
54-
Part.builder()
55-
.functionCall(
56-
FunctionCall.builder()
57-
.id(REQUEST_CONFIRMATION_FUNCTION_CALL_ID)
58-
.name(REQUEST_CONFIRMATION_FUNCTION_CALL_NAME)
59-
.args(
60-
ImmutableMap.of(
61-
"originalFunctionCall",
62-
ImmutableMap.of(
63-
"id",
64-
ORIGINAL_FUNCTION_CALL_ID,
65-
"name",
66-
ECHO_TOOL_NAME,
67-
"args",
68-
ImmutableMap.of("say", "hello"))))
69-
.build())
70-
.build()))
67+
.content(Content.fromParts(Part.builder().functionCall(FUNCTION_CALL).build()))
7168
.build();
7269

7370
private static final Event USER_CONFIRMATION_EVENT =
@@ -78,7 +75,7 @@ public class RequestConfirmationLlmRequestProcessorTest {
7875
Part.builder()
7976
.functionResponse(
8077
FunctionResponse.builder()
81-
.id(REQUEST_CONFIRMATION_FUNCTION_CALL_ID)
78+
.id(FUNCTION_CALL_ID)
8279
.name(REQUEST_CONFIRMATION_FUNCTION_CALL_NAME)
8380
.response(ImmutableMap.of("confirmed", true))
8481
.build())
@@ -93,7 +90,7 @@ public class RequestConfirmationLlmRequestProcessorTest {
9390
Part.builder()
9491
.functionResponse(
9592
FunctionResponse.builder()
96-
.id(REQUEST_CONFIRMATION_FUNCTION_CALL_ID)
93+
.id(FUNCTION_CALL_ID)
9794
.name(REQUEST_CONFIRMATION_FUNCTION_CALL_NAME)
9895
.response(ImmutableMap.of("confirmed", false))
9996
.build())
@@ -208,8 +205,7 @@ public void runAsync_withConfirmationAndToolAlreadyCalled_doesNotCallOriginalFun
208205
FunctionResponse.builder()
209206
.id(ORIGINAL_FUNCTION_CALL_ID)
210207
.name(ECHO_TOOL_NAME)
211-
.response(
212-
ImmutableMap.of("result", ImmutableMap.of("say", "hello")))
208+
.response(ImmutableMap.of("result", ORIGINAL_FUNCTION_CALL_ARGS))
213209
.build())
214210
.build()))
215211
.build();

0 commit comments

Comments
 (0)