类函数(Class Functions)

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

public final class Functions extends Object
这是一个用于处理函数调用的实用类(utility class)。
  • 字段详情

    • REQUEST_CONFIRMATION_FUNCTION_CALL_NAME

      public static final String REQUEST_CONFIRMATION_FUNCTION_CALL_NAME
      用于请求确认功能的函数调用名称。
      See Also:
    • TOOL_CALL_SECURITY_STATES

      public static final String TOOL_CALL_SECURITY_STATES
      用于存储工具调用时安全策略执行结果的会话状态键。
      See Also:
  • 方法详细信息(Method Details)

    • generateClientFunctionCallId

      public static String generateClientFunctionCallId()
      为函数调用生成一个唯一的 ID。
    • populateClientFunctionCallId

      public static void populateClientFunctionCallId(Event modelResponseEvent)
      为提供的事件内容中缺失的函数调用 ID 填充相应的值。

      如果事件中包含没有 ID 的函数调用,该方法会为每个这样的函数调用生成一个唯一的客户端 ID,并更新事件内容。

      Parameters:
      modelResponseEvent - The event potentially containing function calls.
    • populateClientFunctionCallId

      public static void populateClientFunctionCallId(Event modelResponseEvent, UuidProvider uuidProvider)
      使用所提供的信息,填充事件内容中缺失的函数调用 ID。 UuidProvider.
      Parameters:
      modelResponseEvent - The event potentially containing function calls.
      uuidProvider - The provider used to mint new function call IDs.
    • handleFunctionCalls

      public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String,BaseTool> tools)
      处理标准的、非流式的函数调用。
    • handleFunctionCalls

      public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String,BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations)
      处理标准(非流式)函数调用,并提供相应的工具确认功能。
    • handleFunctionCallsLive

      public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String,BaseTool> tools)
      用于处理实时/流式环境中的函数调用,支持后台执行以及流的终止。
    • handleFunctionCallsLive

      public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String,BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations)
      该组件能够在实时/流式环境中处理函数调用,并提供相应的工具确认功能;同时支持后台执行以及流的终止操作。
    • getLongRunningFunctionCalls

      public static Set<String> getLongRunningFunctionCalls(List<com.google.genai.types.FunctionCall> functionCalls, Map<String,BaseTool> tools)
    • findMatchingFunctionCallEvent

      public static Optional<Event> findMatchingFunctionCallEvent(List<Event> events)
      返回最近的一次函数调用事件;该事件的调用 ID 与上一个事件中的函数响应相匹配;如果没有匹配的调用 ID,则返回空值。该功能与 Python ADK 的实现方式相同。 find_matching_function_call.
    • hasPendingLongRunningCall

      public static boolean hasPendingLongRunningCall(Event event)
      该方法用于判断某个事件是否触发了需要长时间运行的函数调用(该函数调用仍在等待响应,例如 HITL 请求)。其功能与 Python ADK v1 的相应功能相同。 should_pause_invocation.
    • generateRequestConfirmationEvent

      public static Optional<Event> generateRequestConfirmationEvent(InvocationContext invocationContext, Event functionCallEvent, Event functionResponseEvent)
      从函数响应事件中生成一个请求确认事件。
      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)
      从事件中获取用户确认请求的函数调用记录。
      Parameters:
      event - The event to extract function calls from.
      Returns:
      A list of function calls for asking user confirmation.