3333import com .google .adk .tools .BaseTool ;
3434import com .google .adk .tools .FunctionTool ;
3535import com .google .adk .tools .ToolContext ;
36- import com .google .common .base .VerifyException ;
3736import com .google .common .collect .ImmutableList ;
3837import com .google .common .collect .ImmutableMap ;
3938import 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
0 commit comments