Skip to content

Commit 5be29d4

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 900942825
1 parent 629c390 commit 5be29d4

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.adk.tools.BaseTool;
3434
import com.google.adk.tools.FunctionTool;
3535
import com.google.adk.tools.ToolContext;
36-
import com.google.common.base.VerifyException;
3736
import com.google.common.collect.ImmutableList;
3837
import com.google.common.collect.ImmutableMap;
3938
import com.google.genai.types.Content;
@@ -141,9 +140,12 @@ public static Maybe<Event> handleFunctionCalls(
141140
Map<String, ToolConfirmation> toolConfirmations) {
142141
ImmutableList<FunctionCall> functionCalls = functionCallEvent.functionCalls();
143142

143+
List<FunctionCall> validFunctionCalls = new ArrayList<>();
144144
for (FunctionCall functionCall : functionCalls) {
145145
if (!tools.containsKey(functionCall.name().get())) {
146-
throw new VerifyException("Tool not found: " + functionCall.name().get());
146+
logger.warn("Tool not found: {}", functionCall.name().get());
147+
} else {
148+
validFunctionCalls.add(functionCall);
147149
}
148150
}
149151

@@ -154,10 +156,10 @@ public static Maybe<Event> handleFunctionCalls(
154156
Observable<Event> functionResponseEventsObservable;
155157
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
156158
functionResponseEventsObservable =
157-
Observable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper);
159+
Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper);
158160
} else {
159161
functionResponseEventsObservable =
160-
Observable.fromIterable(functionCalls)
162+
Observable.fromIterable(validFunctionCalls)
161163
.concatMapEager(call -> functionCallMapper.apply(call).toObservable());
162164
}
163165
return functionResponseEventsObservable
@@ -209,9 +211,12 @@ public static Maybe<Event> handleFunctionCallsLive(
209211
Map<String, ToolConfirmation> toolConfirmations) {
210212
ImmutableList<FunctionCall> functionCalls = functionCallEvent.functionCalls();
211213

214+
List<FunctionCall> validFunctionCalls = new ArrayList<>();
212215
for (FunctionCall functionCall : functionCalls) {
213216
if (!tools.containsKey(functionCall.name().get())) {
214-
throw new VerifyException("Tool not found: " + functionCall.name().get());
217+
logger.warn("Tool not found: {}", functionCall.name().get());
218+
} else {
219+
validFunctionCalls.add(functionCall);
215220
}
216221
}
217222

@@ -222,10 +227,10 @@ public static Maybe<Event> handleFunctionCallsLive(
222227
Observable<Event> responseEventsObservable;
223228
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
224229
responseEventsObservable =
225-
Observable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper);
230+
Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper);
226231
} else {
227232
responseEventsObservable =
228-
Observable.fromIterable(functionCalls)
233+
Observable.fromIterable(validFunctionCalls)
229234
.concatMapEager(call -> functionCallMapper.apply(call).toObservable());
230235
}
231236

@@ -238,7 +243,7 @@ public static Maybe<Event> handleFunctionCallsLive(
238243
if (events.isEmpty()) {
239244
return Maybe.empty();
240245
}
241-
return Maybe.just(Functions.mergeParallelFunctionResponseEvents(events).orElse(null));
246+
return Maybe.fromOptional(Functions.mergeParallelFunctionResponseEvents(events));
242247
});
243248
}
244249

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.adk.testing.TestUtils.createInvocationContext;
2121
import static com.google.adk.testing.TestUtils.createRootAgent;
2222
import static com.google.common.truth.Truth.assertThat;
23-
import static org.junit.Assert.assertThrows;
2423

2524
import com.google.adk.agents.InvocationContext;
2625
import com.google.adk.agents.RunConfig;
@@ -90,11 +89,11 @@ public void handleFunctionCalls_missingTool() {
9089
Part.fromText("..."), Part.fromFunctionCall("missing_tool", ImmutableMap.of())))
9190
.build();
9291

93-
assertThrows(
94-
RuntimeException.class,
95-
() ->
96-
Functions.handleFunctionCalls(
97-
invocationContext, event, /* tools= */ ImmutableMap.of()));
92+
Event functionResponseEvent =
93+
Functions.handleFunctionCalls(invocationContext, event, /* tools= */ ImmutableMap.of())
94+
.blockingGet();
95+
96+
assertThat(functionResponseEvent).isNull();
9897
}
9998

10099
@Test

0 commit comments

Comments
 (0)