Class Functions

java.lang.Object
com.google.adk.flows.llmflows.Functions

public final class Functions extends Object
Utility class for handling function calls.
  • Field Details

    • REQUEST_CONFIRMATION_FUNCTION_CALL_NAME

      public static final String REQUEST_CONFIRMATION_FUNCTION_CALL_NAME
      The function call name for the request confirmation function.
      See Also:
    • TOOL_CALL_SECURITY_STATES

      public static final String TOOL_CALL_SECURITY_STATES
      Session state key for storing the security policy outcomes for tool calls.
      See Also:
  • Method Details

    • generateClientFunctionCallId

      public static String generateClientFunctionCallId()
      Generates a unique ID for a function call.
    • populateClientFunctionCallId

      public static void populateClientFunctionCallId(Event modelResponseEvent)
      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.
    • handleFunctionCalls

      public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String,BaseTool> tools)
      Handles standard, non-streaming function calls.
    • 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

      public 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.
    • 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

      public static Set<String> getLongRunningFunctionCalls(List<com.google.genai.types.FunctionCall> functionCalls, Map<String,BaseTool> tools)
    • 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.