Class SaveFilesAsArtifactsPlugin
java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.SaveFilesAsArtifactsPlugin
- All Implemented Interfaces:
Plugin
Saves files attached to user messages as artifacts, replacing each with a placeholder that names
the artifact so agents can load it later, such as with
LoadArtifactsTool. Each file is saved under its display name, where a user: prefix shares it across the user's sessions, or under a
generated name if it has no display name; files over 20 MB are replaced with an error note
instead. Mirrors Python ADK's SaveFilesAsArtifactsPlugin.-
Field Summary
Fields inherited from class BasePlugin
name -
Constructor Summary
ConstructorsConstructorDescriptionSaveFilesAsArtifactsPlugin(boolean attachFileReference) SaveFilesAsArtifactsPlugin(boolean attachFileReference, String name) Creates the plugin. -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) Reports the versions saved from the user message on the event of the first agent to run, since a plugin cannot add actions to the user's own event.io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) Callback executed when a user message is received before an invocation starts.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) Callback executed after an agent's primary logic has completed.default io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) Callback executed after a response is received from the model.default io.reactivex.rxjava3.core.CompletableafterRunCallback(InvocationContext invocationContext) Callback executed after an ADK runner run has completed.afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) Callback executed after a tool has been called.default io.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest) Callback executed before a request is sent to the model.default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) Callback executed before the ADK runner runs.beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) Callback executed before a tool is called.default io.reactivex.rxjava3.core.Completableclose()Method executed when the runner is closed.default io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) Callback executed after an event is yielded from runner.default io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest, Throwable error) Callback executed when a model call encounters an error.default io.reactivex.rxjava3.core.CompletableonRunErrorCallback(InvocationContext invocationContext, Throwable error) Callback executed when a run encounters an error.onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) Callback executed when a tool call encounters an error.
-
Constructor Details
-
SaveFilesAsArtifactsPlugin
public SaveFilesAsArtifactsPlugin() -
SaveFilesAsArtifactsPlugin
public SaveFilesAsArtifactsPlugin(boolean attachFileReference) -
SaveFilesAsArtifactsPlugin
Creates the plugin.- 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) Description copied from interface:PluginCallback executed when a user message is received before an invocation starts.- 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) Reports the versions saved from the user message on the event of the first agent to run, since a plugin cannot add actions to the user's own event.- 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.
-