CallbackContext

class CallbackContext(invocationContext: InvocationContext, eventActions: EventActions? = null) : ReadonlyContext

The context provided to agents and tools during a callback, such as when a tool is run.

It provides access to the current invocation context, event actions, and state.

Constructors

Link copied to clipboard
constructor(invocationContext: InvocationContext, eventActions: EventActions? = null)

Properties

Link copied to clipboard
Link copied to clipboard
open override val agentName: String

The name of the agent that is being invoked.

Link copied to clipboard
open override val artifactService: ArtifactService?

The ArtifactService instance.

Link copied to clipboard
open override val branch: String?

The branch of the invocation context.

Link copied to clipboard
Link copied to clipboard
open override val invocationId: String

The unique ID of this invocation.

Link copied to clipboard
open override val memoryService: MemoryService?

The MemoryService instance.

Link copied to clipboard
open override val runConfig: RunConfig?

The run configuration for this invocation.

Link copied to clipboard
open override val session: Session

The session that this invocation is a part of.

Link copied to clipboard
open override val state: Map<String, Any>

The state of the session.

Link copied to clipboard
open override val userContent: Content?

The user content that this invocation is processing.

Link copied to clipboard
open override val userId: String

The user ID of the user that initiated the session.

Functions

Link copied to clipboard
suspend fun addSessionToMemory()

Triggers memory generation for the current session.

Link copied to clipboard

Requests the current LLM agent to stop after the current step completes.

Link copied to clipboard
open suspend override fun getEvents(currentInvocation: Boolean, currentBranch: Boolean): List<Event>

Returns the events from the current session.

Link copied to clipboard
suspend fun listArtifacts(): List<String>

Lists the artifact names visible to this invocation. Returns an empty list if no artifact service is configured.

Link copied to clipboard
suspend fun loadArtifact(name: String, version: Int? = null): Part?

Loads an artifact by name from the invocation's com.google.adk.kt.artifacts.ArtifactService. Returns null if no artifact service is configured or the artifact is not found.

Link copied to clipboard

Merges the given event actions into the current event actions.

Link copied to clipboard
suspend fun saveArtifact(name: String, artifact: Part): Int

Saves artifact under name on the invocation's com.google.adk.kt.artifacts.ArtifactService, records the new version into eventActions' artifactDelta, and returns the version.

Link copied to clipboard
fun updateState(key: String, value: Any)

Updates the state delta in the event actions.