Class Functions
java.lang.Object
com.google.adk.flows.llmflows.Functions
Utility class for handling function calls.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfindMatchingFunctionCallEvent(List<Event> events) Returns the most recent function-call event whose call id matches a function response in the last event, or empty.static StringGenerates a unique ID for a function call.generateRequestConfirmationEvent(InvocationContext invocationContext, Event functionCallEvent, Event functionResponseEvent) Generates a request confirmation event from a function response event.static com.google.common.collect.ImmutableList<com.google.genai.types.FunctionCall> Gets the ask user confirmation function calls from the event.getLongRunningFunctionCalls(List<com.google.genai.types.FunctionCall> functionCalls, Map<String, BaseTool> tools) static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools) Handles standard, non-streaming function calls.static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) Handles standard, non-streaming function calls with tool confirmations.static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools) Handles function calls in a live/streaming context, supporting background execution and stream termination.static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) Handles function calls in a live/streaming context with tool confirmations, supporting background execution and stream termination.static booleanhasPendingLongRunningCall(Event event) Returns whether the event emits a long-running function call still awaiting a response (e.g.static voidpopulateClientFunctionCallId(Event modelResponseEvent) Populates missing function call IDs in the provided event's content.static voidpopulateClientFunctionCallId(Event modelResponseEvent, UuidProvider uuidProvider) Populates missing function call IDs in the provided event's content using the givenUuidProvider.
-
Field Details
-
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME
The function call name for the request confirmation function.- See Also:
-
TOOL_CALL_SECURITY_STATES
Session state key for storing the security policy outcomes for tool calls.- See Also:
-
-
Method Details
-
generateClientFunctionCallId
Generates a unique ID for a function call. -
populateClientFunctionCallId
Populates missing function call IDs in the provided event's content.If the event contains function calls without an ID, this method generates a unique client-side ID for each and updates the event content.
- Parameters:
modelResponseEvent- The event potentially containing function calls.
-
populateClientFunctionCallId
public static void populateClientFunctionCallId(Event modelResponseEvent, UuidProvider uuidProvider) Populates missing function call IDs in the provided event's content using the givenUuidProvider.- Parameters:
modelResponseEvent- The event potentially containing function calls.uuidProvider- The provider used to mint new function call IDs.
-
handleFunctionCalls
-
handleFunctionCalls
public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) Handles standard, non-streaming function calls with tool confirmations. -
handleFunctionCallsLive
-
handleFunctionCallsLive
public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) Handles function calls in a live/streaming context with tool confirmations, supporting background execution and stream termination. -
getLongRunningFunctionCalls
-
findMatchingFunctionCallEvent
-
hasPendingLongRunningCall
Returns whether the event emits a long-running function call still awaiting a response (e.g. a HITL request). Mirrors Python ADK v1'sshould_pause_invocation. -
generateRequestConfirmationEvent
public static Optional<Event> generateRequestConfirmationEvent(InvocationContext invocationContext, Event functionCallEvent, Event functionResponseEvent) Generates a request confirmation event from a function response event.- Parameters:
invocationContext- The invocation context.functionCallEvent- The event containing the original function call.functionResponseEvent- The event containing the function response.- Returns:
- An optional event containing the request confirmation function call.
-
getAskUserConfirmationFunctionCalls
public static com.google.common.collect.ImmutableList<com.google.genai.types.FunctionCall> getAskUserConfirmationFunctionCalls(Event event) Gets the ask user confirmation function calls from the event.- Parameters:
event- The event to extract function calls from.- Returns:
- A list of function calls for asking user confirmation.
-