类:GlobalInstructionPlugin
java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.GlobalInstructionPlugin
- All Implemented Interfaces:
Plugin
该插件在应用程序(App)层面提供了全局指令功能。
全局指令适用于应用程序中的所有代理(agent),为设置适用于整个应用程序的指令、标识符或“特性”提供了一种统一的方式。这些全局指令可以以静态字符串的形式提供,也可以作为函数的形式提供;后者会根据特定条件来解析并执行相应的指令。 CallbackContext.
该插件通过 `before_model_callback` 函数来发挥作用,从而能够在 LLM(大型语言模型)的请求被发送到模型之前对其进行修改。具体来说,它会将一条全局指令添加到代理提供的任何现有系统指令之前。
-
字段摘要
Fields inherited from class BasePlugin
name -
构造函数概述
ConstructorsConstructorDescriptionGlobalInstructionPlugin(String globalInstruction) GlobalInstructionPlugin(String globalInstruction, String name) GlobalInstructionPlugin(Function<CallbackContext, io.reactivex.rxjava3.core.Maybe<String>> instructionProvider) GlobalInstructionPlugin(Function<CallbackContext, io.reactivex.rxjava3.core.Maybe<String>> instructionProvider, String name) -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest) 在请求被发送到模型之前,会先执行这个回调函数。Methods inherited from class BasePlugin
getNameMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Plugin
afterAgentCallback, afterModelCallback, afterRunCallback, afterToolCallback, beforeAgentCallback, beforeRunCallback, beforeToolCallback, close, onEventCallback, onModelErrorCallback, onRunErrorCallback, onToolErrorCallback, onUserMessageCallbackModifier and TypeMethodDescriptiondefault io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> afterAgentCallback(BaseAgent agent, CallbackContext callbackContext) 在代理程序的主要逻辑执行完成后,会触发该回调函数。default io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) 在从模型接收到响应后,会执行该回调函数。default io.reactivex.rxjava3.core.CompletableafterRunCallback(InvocationContext invocationContext) 在 ADK 运行器完成运行后,会执行该回调函数。afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) 在某个工具被调用之后,会执行相应的回调函数。default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) 回调函数在代理程序的主要逻辑被执行之前被调用。default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) 回调函数在 ADK 运行程序启动之前被执行。beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) 回调函数在工具被调用之前执行。default io.reactivex.rxjava3.core.Completableclose()当运行器(runner)被关闭时,会执行此方法。default io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) 在事件从运行器(runner)中被处理/执行后,会触发相应的回调函数(Callback)。default io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest, Throwable error) 当模型调用遇到错误时,会执行此回调函数。default io.reactivex.rxjava3.core.CompletableonRunErrorCallback(InvocationContext invocationContext, Throwable error) 当运行过程中遇到错误时,会执行此回调函数。onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) 当工具调用遇到错误时,会执行此回调函数。default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) 当在调用开始之前接收到用户消息时,会执行此回调函数。
-
构造函数详细信息
-
GlobalInstructionPlugin
-
GlobalInstructionPlugin
-
GlobalInstructionPlugin
public GlobalInstructionPlugin(Function<CallbackContext, io.reactivex.rxjava3.core.Maybe<String>> instructionProvider) -
GlobalInstructionPlugin
public GlobalInstructionPlugin(Function<CallbackContext, io.reactivex.rxjava3.core.Maybe<String>> instructionProvider, String name)
-
-
方法详细信息(Method Details)
-
beforeModelCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest) 描述内容复制自接口文档:Plugin在请求被发送到模型之前,会先执行这个回调函数。- Parameters:
callbackContext- The context for the current agent call.llmRequest- The mutable request builder, allowing modification of the request before it is sent to the model.- Returns:
- An optional LlmResponse to trigger an early exit. Returning Empty to proceed normally.
-