类:PluginManager
java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.PluginManager
- All Implemented Interfaces:
Plugin
负责插件的注册与管理,以及插件的执行过程。
`PluginManager` 是一个内部类,它负责在 SDK 执行生命周期的关键阶段调用插件对应的回调函数(即插件提供的处理逻辑)。
-
字段摘要
Fields inherited from class BasePlugin
name -
构造函数概述
Constructors -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> afterAgentCallback(BaseAgent agent, CallbackContext callbackContext) 在代理程序的主要逻辑执行完成后,会触发该回调函数。io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) 在从模型接收到响应后,会执行该回调函数。io.reactivex.rxjava3.core.CompletableafterRunCallback(InvocationContext invocationContext) 在 ADK 运行器完成运行后,会执行该回调函数。afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) 在某个工具被调用之后,会执行相应的回调函数。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) 回调函数在代理程序的主要逻辑被执行之前被调用。io.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest) 在请求被发送到模型之前,会先执行这个回调函数。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) 回调函数在 ADK 运行程序启动之前被执行。beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) 回调函数在工具被调用之前执行。io.reactivex.rxjava3.core.Completableclose()当运行器(runner)被关闭时,会执行此方法。根据名称检索已注册的插件。返回已注册的插件列表。io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) 在事件从运行器(runner)中被处理/执行后,会触发相应的回调函数(Callback)。io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest, Throwable error) 当模型调用遇到错误时,会执行此回调函数。io.reactivex.rxjava3.core.CompletableonRunErrorCallback(InvocationContext invocationContext, Throwable error) 当运行过程中遇到错误时,会执行此回调函数。onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) 当工具调用遇到错误时,会执行此回调函数。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) 当在调用开始之前接收到用户消息时,会执行此回调函数。voidregisterPlugin(Plugin plugin) 注册一个新的插件。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> runBeforeRunCallback(InvocationContext invocationContext) io.reactivex.rxjava3.core.CompletablerunOnRunErrorCallback(InvocationContext invocationContext, Throwable error) io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> runOnUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) Methods inherited from class BasePlugin
getName
-
构造函数详细信息
-
PluginManager
-
PluginManager
public PluginManager()
-
-
方法详细信息(Method Details)
-
registerPlugin
注册一个新的插件。- Parameters:
plugin- The plugin instance to register.- Throws:
IllegalArgumentException- If a plugin with the same name is already registered.
-
getPlugin
根据名称检索已注册的插件。- Parameters:
pluginName- The name of the plugin to retrieve.- Returns:
- The plugin instance if found, otherwise
Optional.empty().
-
getPlugins
-
runOnUserMessageCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> runOnUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) -
onUserMessageCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) 描述内容复制自接口文档:Plugin当在调用开始之前接收到用户消息时,会执行此回调函数。- Parameters:
invocationContext- The context for the entire invocation.userMessage- The message content input by user.- Returns:
- An optional Content to replace the user message. Returning Empty to proceed normally.
-
runBeforeRunCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> runBeforeRunCallback(InvocationContext invocationContext) -
beforeRunCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) 描述内容复制自接口文档:Plugin回调函数在 ADK 运行程序启动之前被执行。- Parameters:
invocationContext- The context for the entire invocation.- Returns:
- An optional Content to halt execution. Returning Empty to proceed normally.
-
afterRunCallback
描述内容复制自接口文档:Plugin在 ADK 运行器完成运行后,会执行该回调函数。- Parameters:
invocationContext- The context for the entire invocation.
-
runOnRunErrorCallback
public io.reactivex.rxjava3.core.Completable runOnRunErrorCallback(InvocationContext invocationContext, Throwable error) -
onRunErrorCallback
public io.reactivex.rxjava3.core.Completable onRunErrorCallback(InvocationContext invocationContext, Throwable error) 描述内容复制自接口文档:Plugin当运行过程中遇到错误时,会执行此回调函数。- Parameters:
invocationContext- The context for the entire invocation.error- The exception that was raised.
-
close
public io.reactivex.rxjava3.core.Completable close()描述内容复制自接口文档:Plugin当运行器(runner)被关闭时,会执行此方法。此方法用于执行清理任务,例如关闭网络连接或释放资源。
-
onEventCallback
public io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) 描述内容复制自接口文档:Plugin在事件从运行器(runner)中被处理/执行后,会触发相应的回调函数(Callback)。- Parameters:
invocationContext- The context for the entire invocation.event- The event raised by the runner.- Returns:
- An optional Event to modify or replace the response. Returning Empty to proceed normally.
-
beforeAgentCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) 描述内容复制自接口文档:Plugin回调函数在代理程序的主要逻辑被执行之前被调用。- Parameters:
agent- The agent that is about to run.callbackContext- The context for the agent invocation.- Returns:
- An optional Content object to bypass the agent's execution. Returning Empty to proceed normally.
-
afterAgentCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> afterAgentCallback(BaseAgent agent, CallbackContext callbackContext) 描述内容复制自接口文档:Plugin在代理程序的主要逻辑执行完成后,会触发该回调函数。- Parameters:
agent- The agent that has just run.callbackContext- The context for the agent invocation.- Returns:
- An optional Content object to replace the agent's original result. Returning Empty to use the original result.
-
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.
-
afterModelCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) 描述内容复制自接口文档:Plugin在从模型接收到响应后,会执行该回调函数。- Parameters:
callbackContext- The context for the current agent call.llmResponse- The response object received from the model.- Returns:
- An optional LlmResponse to modify or replace the response. Returning Empty to use the original response.
-
onModelErrorCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest, Throwable error) 描述内容复制自接口文档:Plugin当模型调用遇到错误时,会执行此回调函数。- Parameters:
callbackContext- The context for the current agent call.llmRequest- The mutable request builder for the request that failed.error- The exception that was raised.- Returns:
- An optional LlmResponse to use instead of propagating the error. Returning Empty to allow the original error to be raised.
-
beforeToolCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) 描述内容复制自接口文档:Plugin回调函数在工具被调用之前执行。- Parameters:
tool- The tool instance that is about to be executed.toolArgs- The dictionary of arguments to be used for invoking the tool.toolContext- The context specific to the tool execution.- Returns:
- An optional Map to stop the tool execution and return this response immediately. Returning Empty to proceed normally.
-
afterToolCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) 描述内容复制自接口文档:Plugin在某个工具被调用之后,会执行相应的回调函数。- Parameters:
tool- The tool instance that has just been executed.toolArgs- The original arguments that were passed to the tool.toolContext- The context specific to the tool execution.result- The dictionary returned by the tool invocation.- Returns:
- An optional Map to replace the original result from the tool. Returning Empty to use the original result.
-
onToolErrorCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) 描述内容复制自接口文档:Plugin当工具调用遇到错误时,会执行此回调函数。- Parameters:
tool- The tool instance that encountered an error.toolArgs- The arguments that were passed to the tool.toolContext- The context specific to the tool execution.error- The exception that was raised during tool execution.- Returns:
- An optional Map to be used as the tool response instead of propagating the error. Returning Empty to allow the original error to be raised.
-