SaveFilesAsArtifactsPlugin

class SaveFilesAsArtifactsPlugin @JvmOverloads constructor(attachFileReference: Boolean = true, val name: String = "save_files_as_artifacts_plugin") : 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.

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).

Constructors

Link copied to clipboard
constructor(attachFileReference: Boolean = true, name: String = "save_files_as_artifacts_plugin")

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val name: String

The unique name of the plugin instance.

Functions

Link copied to clipboard
open suspend fun afterAgent(context: CallbackContext): CallbackChoice<Unit, Content>

Callback executed after a specific agent finishes its processing.

Link copied to clipboard
open suspend fun afterModel(context: CallbackContext, response: LlmResponse): LlmResponse

Callback executed after an LLM response is received.

Link copied to clipboard
open suspend fun afterRun(invocationContext: InvocationContext)

Callback executed after the ADK runner completes its execution.

Link copied to clipboard
open suspend fun afterTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, result: Map<String, Any?>): Map<String, Any?>

Callback executed after a tool runs, or after a before-tool callback answers the call in its place.

Link copied to clipboard
open suspend override fun beforeAgent(context: CallbackContext): CallbackChoice<EventActions, Content>

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.

Link copied to clipboard

Callback executed before an LLM request is sent.

Link copied to clipboard
open suspend fun beforeRun(invocationContext: InvocationContext): CallbackChoice<Unit, Content>

Callback executed before the ADK runner starts the main execution loop.

Link copied to clipboard
open suspend fun beforeTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>): CallbackChoice<Map<String, Any?>, Map<String, Any?>>

Callback executed before a tool is invoked.

Link copied to clipboard
open override fun close()

Method executed when the runner is closed.

Link copied to clipboard
open suspend fun onEvent(invocationContext: InvocationContext, event: Event): Event

Callback executed when an event is yielded by an agent during execution.

Link copied to clipboard
open suspend fun onModelError(context: CallbackContext, request: LlmRequest, error: Throwable): CallbackChoice<Unit, LlmResponse>

Callback executed when an error occurs during an LLM interaction.

Link copied to clipboard
open suspend fun onRunError(invocationContext: InvocationContext, error: Throwable)

Callback executed when an unhandled error escapes the ADK runner run.

Link copied to clipboard
open suspend fun onToolError(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, error: Throwable): CallbackChoice<Unit, Map<String, Any?>>

Callback executed when an error occurs during a tool invocation.

Link copied to clipboard
open suspend override fun onUserMessage(invocationContext: InvocationContext, userMessage: Content): Content

Callback executed when a user message is received before an invocation starts.