Class SaveFilesAsArtifactsPlugin

java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.SaveFilesAsArtifactsPlugin
All Implemented Interfaces:
Plugin

public class SaveFilesAsArtifactsPlugin extends BasePlugin
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.
  • Constructor Details

    • SaveFilesAsArtifactsPlugin

      public SaveFilesAsArtifactsPlugin()
    • SaveFilesAsArtifactsPlugin

      public SaveFilesAsArtifactsPlugin(boolean attachFileReference)
    • SaveFilesAsArtifactsPlugin

      public SaveFilesAsArtifactsPlugin(boolean attachFileReference, String name)
      Creates the plugin.
      Parameters:
      attachFileReference - Whether to also attach a FileData reference to each saved file when the artifact service stores it at a URI the model can read (gs, https or http).
      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: Plugin
      Callback 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.