Skip to content

Commit 44b98ef

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Make FunctionResponses respect the order of FunctionCalls
PiperOrigin-RevId: 845729296
1 parent 43613a4 commit 44b98ef

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import io.reactivex.rxjava3.core.Maybe;
4848
import io.reactivex.rxjava3.core.Single;
4949
import io.reactivex.rxjava3.disposables.Disposable;
50-
import io.reactivex.rxjava3.functions.Function;
5150
import java.util.ArrayList;
5251
import java.util.Collections;
5352
import java.util.HashMap;
@@ -57,6 +56,7 @@
5756
import java.util.Optional;
5857
import java.util.Set;
5958
import java.util.UUID;
59+
import java.util.function.Function;
6060
import org.slf4j.Logger;
6161
import org.slf4j.LoggerFactory;
6262

@@ -202,10 +202,12 @@ public static Maybe<Event> handleFunctionCalls(
202202
Flowable<Event> functionResponseEventsFlowable;
203203
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
204204
functionResponseEventsFlowable =
205-
Flowable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper);
205+
Flowable.fromIterable(functionCalls)
206+
.concatMapMaybe(call -> functionCallMapper.apply(call));
206207
} else {
207208
functionResponseEventsFlowable =
208-
Flowable.fromIterable(functionCalls).flatMapMaybe(functionCallMapper);
209+
Flowable.fromIterable(functionCalls)
210+
.concatMapEager(call -> functionCallMapper.apply(call).toFlowable());
209211
}
210212
return functionResponseEventsFlowable
211213
.toList()
@@ -314,11 +316,12 @@ public static Maybe<Event> handleFunctionCallsLive(
314316

315317
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
316318
responseEventsFlowable =
317-
Flowable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper);
318-
319+
Flowable.fromIterable(functionCalls)
320+
.concatMapMaybe(call -> functionCallMapper.apply(call));
319321
} else {
320322
responseEventsFlowable =
321-
Flowable.fromIterable(functionCalls).flatMapMaybe(functionCallMapper);
323+
Flowable.fromIterable(functionCalls)
324+
.concatMapEager(call -> functionCallMapper.apply(call).toFlowable());
322325
}
323326

324327
return responseEventsFlowable

0 commit comments

Comments
 (0)