From daf008aa9fbd823cf5031660173d30e97dfa6e50 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Fri, 10 Apr 2026 14:05:57 -0700 Subject: [PATCH] ADK changes PiperOrigin-RevId: 897878883 --- .../google/adk/flows/llmflows/Functions.java | 21 ++++++++++++------- .../adk/flows/llmflows/FunctionsTest.java | 11 +++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/com/google/adk/flows/llmflows/Functions.java b/core/src/main/java/com/google/adk/flows/llmflows/Functions.java index 0b0e5b4d5..bc810f28f 100644 --- a/core/src/main/java/com/google/adk/flows/llmflows/Functions.java +++ b/core/src/main/java/com/google/adk/flows/llmflows/Functions.java @@ -33,7 +33,6 @@ import com.google.adk.tools.BaseTool; import com.google.adk.tools.FunctionTool; import com.google.adk.tools.ToolContext; -import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.genai.types.Content; @@ -141,9 +140,12 @@ public static Maybe handleFunctionCalls( Map toolConfirmations) { ImmutableList functionCalls = functionCallEvent.functionCalls(); + List validFunctionCalls = new ArrayList<>(); for (FunctionCall functionCall : functionCalls) { if (!tools.containsKey(functionCall.name().get())) { - throw new VerifyException("Tool not found: " + functionCall.name().get()); + logger.warn("Tool not found: {}", functionCall.name().get()); + } else { + validFunctionCalls.add(functionCall); } } @@ -154,10 +156,10 @@ public static Maybe handleFunctionCalls( Observable functionResponseEventsObservable; if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) { functionResponseEventsObservable = - Observable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper); + Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper); } else { functionResponseEventsObservable = - Observable.fromIterable(functionCalls) + Observable.fromIterable(validFunctionCalls) .concatMapEager(call -> functionCallMapper.apply(call).toObservable()); } return functionResponseEventsObservable @@ -209,9 +211,12 @@ public static Maybe handleFunctionCallsLive( Map toolConfirmations) { ImmutableList functionCalls = functionCallEvent.functionCalls(); + List validFunctionCalls = new ArrayList<>(); for (FunctionCall functionCall : functionCalls) { if (!tools.containsKey(functionCall.name().get())) { - throw new VerifyException("Tool not found: " + functionCall.name().get()); + logger.warn("Tool not found: {}", functionCall.name().get()); + } else { + validFunctionCalls.add(functionCall); } } @@ -222,10 +227,10 @@ public static Maybe handleFunctionCallsLive( Observable responseEventsObservable; if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) { responseEventsObservable = - Observable.fromIterable(functionCalls).concatMapMaybe(functionCallMapper); + Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper); } else { responseEventsObservable = - Observable.fromIterable(functionCalls) + Observable.fromIterable(validFunctionCalls) .concatMapEager(call -> functionCallMapper.apply(call).toObservable()); } @@ -238,7 +243,7 @@ public static Maybe handleFunctionCallsLive( if (events.isEmpty()) { return Maybe.empty(); } - return Maybe.just(Functions.mergeParallelFunctionResponseEvents(events).orElse(null)); + return Maybe.fromOptional(Functions.mergeParallelFunctionResponseEvents(events)); }); } diff --git a/core/src/test/java/com/google/adk/flows/llmflows/FunctionsTest.java b/core/src/test/java/com/google/adk/flows/llmflows/FunctionsTest.java index d5db4d4b3..1b8de4e4f 100644 --- a/core/src/test/java/com/google/adk/flows/llmflows/FunctionsTest.java +++ b/core/src/test/java/com/google/adk/flows/llmflows/FunctionsTest.java @@ -20,7 +20,6 @@ import static com.google.adk.testing.TestUtils.createInvocationContext; import static com.google.adk.testing.TestUtils.createRootAgent; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; import com.google.adk.agents.InvocationContext; import com.google.adk.agents.RunConfig; @@ -90,11 +89,11 @@ public void handleFunctionCalls_missingTool() { Part.fromText("..."), Part.fromFunctionCall("missing_tool", ImmutableMap.of()))) .build(); - assertThrows( - RuntimeException.class, - () -> - Functions.handleFunctionCalls( - invocationContext, event, /* tools= */ ImmutableMap.of())); + Event functionResponseEvent = + Functions.handleFunctionCalls(invocationContext, event, /* tools= */ ImmutableMap.of()) + .blockingGet(); + + assertThat(functionResponseEvent).isNull(); } @Test