Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ private static boolean isEventBelongsToBranch(Optional<String> invocationBranchO
* @return A new list of events with the appropriate rearrangement.
*/
private static List<Event> rearrangeEventsForLatestFunctionResponse(List<Event> events) {
if (events.size() < 2) {
// No need to process, since there is no function_call.
return events;
}

// TODO: b/412663475 - Handle parallel function calls within the same event. Currently, this
// throws an error.
if (events.isEmpty() || Iterables.getLast(events).functionResponses().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public void rearrangeLatest_multipleFRsForSameFCAsync_returnsMergedFR() {
@Test
public void rearrangeLatest_missingFCEvent_throwsException() {
Event frEvent = createFunctionResponseEvent("fr1", "tool1", "call1");
ImmutableList<Event> events = ImmutableList.of(createUserEvent("u1", "Query"), frEvent);
Event frEvent2 = createFunctionResponseEvent("fr2", "tool1", "call1");
ImmutableList<Event> events =
ImmutableList.of(createUserEvent("u1", "Query"), frEvent, frEvent2);

assertThrows(IllegalStateException.class, () -> runContentsProcessor(events));
}
Expand Down Expand Up @@ -473,10 +475,12 @@ public void processRequest_includeContentsNone_asyncFRAcrossTurns_throwsExceptio
Event fc1 = createFunctionCallEvent("fc1", "tool1", "call1");
Event u2 = createUserEvent("u2", "Query 2");
Event fr1 = createFunctionResponseEvent("fr1", "tool1", "call1"); // FR for fc1
Event fr2 = createFunctionResponseEvent("fr2", "tool2", "call1"); // FR for fc2

ImmutableList<Event> events = ImmutableList.of(u1, fc1, u2, fr1);
ImmutableList<Event> events = ImmutableList.of(u1, fc1, u2, fr1, fr2);

// The current turn starts from u2. fc1 is not in the sublist [u2, fr1], so rearrangement fails.
// The current turn starts from u2. fc1 is not in the sublist [u2, fr1, fr2], so rearrangement
// fails.
IllegalStateException e =
assertThrows(
IllegalStateException.class,
Expand Down