类:SaveFilesAsArtifactsPlugin
java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.SaveFilesAsArtifactsPlugin
- All Implemented Interfaces:
Plugin
将用户消息中附带的文件保存为“工件”(artifacts),并用一个占位符来替换这些文件;该占位符会为这些工件指定名称,以便代理程序(agents)日后能够加载这些文件。
LoadArtifactsTool每个文件都会以其原始文件名保存。 display name其中,a user: 前缀(prefix)会在用户的各个会话中保持一致;如果某个文件没有显示名称(display name),则会使用一个自动生成的名称来标识该文件。对于大小超过 20 MB 的文件,系统会用错误提示信息来替代这些文件。该功能实现了与 Python ADK 相同的功能(即对文件进行统一管理和处理)。 SaveFilesAsArtifactsPlugin.-
字段摘要
Fields inherited from class BasePlugin
name -
构造函数概述
ConstructorsConstructorDescriptionSaveFilesAsArtifactsPlugin(boolean attachFileReference) SaveFilesAsArtifactsPlugin(boolean attachFileReference, String name) 创建该插件。 -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) 该功能用于报告从用户消息中保存的版本信息;这些版本信息是在第一个代理程序开始运行时被记录下来的。需要注意的是:插件无法直接为用户自己的事件添加额外的操作(即无法修改用户事件的处理流程)。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) 当在调用开始之前接收到用户消息时,会执行此回调函数。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, beforeModelCallback, beforeRunCallback, beforeToolCallback, close, onEventCallback, onModelErrorCallback, onRunErrorCallback, onToolErrorCallbackModifier 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<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest) 在请求被发送到模型之前,会先执行这个回调函数。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) 当工具调用遇到错误时,会执行此回调函数。
-
构造函数详细信息
-
SaveFilesAsArtifactsPlugin
public SaveFilesAsArtifactsPlugin() -
SaveFilesAsArtifactsPlugin
public SaveFilesAsArtifactsPlugin(boolean attachFileReference) -
SaveFilesAsArtifactsPlugin
创建该插件。- Parameters:
attachFileReference- Whether to also attach aFileDatareference to each saved file when the artifact service stores it at a URI the model can read (gs,httpsorhttp).name- The unique name of the plugin instance.
-
-
方法详细信息(Method Details)
-
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.
-
beforeAgentCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) 该功能用于报告从用户消息中保存的版本信息;这些版本信息是在第一个代理程序开始运行时被记录下来的。需要注意的是:插件无法直接为用户自己的事件添加额外的操作(即无法修改用户事件的处理流程)。- 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.
-