类函数(Class Functions)
java.lang.Object
com.google.adk.flows.llmflows.Functions
这是一个用于处理函数调用的实用类(utility class)。
-
字段摘要
Fields -
方法概述
Modifier and TypeMethodDescriptionfindMatchingFunctionCallEvent(List<Event> events) 返回最近的一次函数调用事件;该事件的调用 ID 与上一个事件中的函数响应相匹配;如果没有匹配的调用 ID,则返回空值。static String为函数调用生成一个唯一的 ID。generateRequestConfirmationEvent(InvocationContext invocationContext, Event functionCallEvent, Event functionResponseEvent) 从函数响应事件中生成一个请求确认事件。static com.google.common.collect.ImmutableList<com.google.genai.types.FunctionCall> 从事件中获取用户确认请求的函数调用记录。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) 处理标准的、非流式的函数调用。static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) 处理标准(非流式)函数调用,并提供相应的工具确认功能。static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools) 用于处理实时/流式环境中的函数调用,支持后台执行以及流的终止。static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) 该组件能够在实时/流式环境中处理函数调用,并提供相应的工具确认功能;同时支持后台执行以及流的终止操作。static booleanhasPendingLongRunningCall(Event event) 该方法用于判断该事件是否触发了某个需要长时间运行(且尚未收到响应)的函数调用。static voidpopulateClientFunctionCallId(Event modelResponseEvent) 为提供的事件内容中缺失的函数调用 ID 填充相应的值。static voidpopulateClientFunctionCallId(Event modelResponseEvent, UuidProvider uuidProvider) 使用所提供的信息,填充事件内容中缺失的函数调用 ID。UuidProvider.
-
字段详情
-
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME
-
TOOL_CALL_SECURITY_STATES
-
-
方法详细信息(Method Details)
-
generateClientFunctionCallId
为函数调用生成一个唯一的 ID。 -
populateClientFunctionCallId
为提供的事件内容中缺失的函数调用 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
-
handleFunctionCalls
public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCalls(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) 处理标准(非流式)函数调用,并提供相应的工具确认功能。 -
handleFunctionCallsLive
-
handleFunctionCallsLive
public static io.reactivex.rxjava3.core.Maybe<Event> handleFunctionCallsLive(InvocationContext invocationContext, Event functionCallEvent, Map<String, BaseTool> tools, Map<String, ToolConfirmation> toolConfirmations) 该组件能够在实时/流式环境中处理函数调用,并提供相应的工具确认功能;同时支持后台执行以及流的终止操作。 -
getLongRunningFunctionCalls
-
findMatchingFunctionCallEvent
-
hasPendingLongRunningCall
该方法用于判断某个事件是否触发了需要长时间运行的函数调用(该函数调用仍在等待响应,例如 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.
-