Class InvocationContext
java.lang.Object
com.google.adk.agents.InvocationContext
The context for an agent invocation.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a map of tool call IDs to active streaming tools for the current invocation.agent()Returns the agent being invoked.Returns an unmodifiable view of the per-agent resumability checkpoint states for this invocation, keyed by agent name.appName()Returns the application name associated with the session.Returns the artifact service for persisting artifacts.branch()Returns the branch ID for the current invocation, if one is set.voidSets the [branch] ID for the current invocation.static InvocationContext.Builderbuilder()Returns a newInvocationContext.Builderfor creatingInvocationContextinstances.Returns a map for storing temporary context data that can be shared between different parts of the invocation (e.g., before/on/after model callbacks).Returns the context cache configuration for the current agent run.booleanReturns whether this invocation should be ended, e.g., due to reaching a terminal state or error.Returns an unmodifiable view of the per-agent end-of-agent flags for this invocation, keyed by agent name.booleancom.google.common.collect.ImmutableList<Event> events(boolean currentInvocation, boolean currentBranch) Returns the current session's events, optionally filtered to the current invocation and/or the current branch.Returns the events compaction configuration for the current agent run.com.google.common.collect.ImmutableList<Event> Returns a snapshot of the session's events, keeping only those on the branch this invocation is running on.inthashCode()voidIncrements the count of LLM calls made during this invocation and throws an exception if the limit defined inRunConfigis exceeded.Returns the unique ID for this invocation.booleanDeprecated.booleanReturns whether the current invocation is resumable.Returns the queue for managing live requests, if available for this invocation.Returns the memory service for accessing agent memory.static StringGenerates a new unique ID for an invocation context.Returns the plugin manager for accessing tools and plugins.voidRehydratesagentStates()andendOfAgents()from the current invocation's history when this invocation is resumable.Returns the configuration for the current agent run.session()Returns the session associated with this invocation.Returns the session service for managing session state.voidsetEndInvocation(boolean endInvocation) Sets whether this invocation should be ended.booleanshouldPauseInvocation(Event event) Returns whether to pause the invocation right after this event: it is resumable and the event carries a long-running function call, including a syntheticadk_request_confirmationHITL request.Returns aInvocationContext.Builderinitialized with the values of this instance.Optional<com.google.genai.types.Content> Returns the user content that triggered this invocation, if any.userId()Returns the user ID associated with the session.
-
Constructor Details
-
InvocationContext
-
-
Method Details
-
builder
Returns a newInvocationContext.Builderfor creatingInvocationContextinstances. -
toBuilder
Returns aInvocationContext.Builderinitialized with the values of this instance. -
sessionService
Returns the session service for managing session state. -
artifactService
Returns the artifact service for persisting artifacts. -
memoryService
Returns the memory service for accessing agent memory. -
pluginManager
Returns the plugin manager for accessing tools and plugins. -
activeStreamingTools
Returns a map of tool call IDs to active streaming tools for the current invocation. -
liveRequestQueue
Returns the queue for managing live requests, if available for this invocation. -
invocationId
Returns the unique ID for this invocation. -
branch
Sets the [branch] ID for the current invocation. A branch represents a fork in the conversation history. -
branch
-
agent
Returns the agent being invoked. -
session
Returns the session associated with this invocation. -
eventsOnCurrentBranch
Returns a snapshot of the session's events, keeping only those on the branch this invocation is running on.The rule is author-asymmetric on purpose, so a confirmation the user answered on a sub-branch stays visible while a descendant agent's own events do not.
-
userContent
Returns the user content that triggered this invocation, if any. -
runConfig
Returns the configuration for the current agent run. -
callbackContextData
-
endInvocation
public boolean endInvocation()Returns whether this invocation should be ended, e.g., due to reaching a terminal state or error. -
setEndInvocation
public void setEndInvocation(boolean endInvocation) Sets whether this invocation should be ended. -
appName
Returns the application name associated with the session. -
userId
Returns the user ID associated with the session. -
newInvocationContextId
Generates a new unique ID for an invocation context. -
incrementLlmCallsCount
Increments the count of LLM calls made during this invocation and throws an exception if the limit defined inRunConfigis exceeded.- Throws:
LlmCallsLimitExceededException- if the call limit is exceeded
-
eventsCompactionConfig
Returns the events compaction configuration for the current agent run. -
contextCacheConfig
Returns the context cache configuration for the current agent run. -
isResumable
Returns whether the current invocation is resumable. -
isLegacyResumability
Deprecated.Reports the deprecated plain-text continuation shim and goes away with it; useisResumable().Returns whether the invocation runs the legacy resumption flow: the behaviorisResumable()had before durable checkpoints existed. It is a separate flow, not a weakerisResumable(), so a caller wanting either has to ask for both. -
agentStates
Returns an unmodifiable view of the per-agent resumability checkpoint states for this invocation, keyed by agent name. The backing map is shared by reference across derived contexts within the invocation; mutate it only throughsetAgentState(String, Map, boolean). -
endOfAgents
Returns an unmodifiable view of the per-agent end-of-agent flags for this invocation, keyed by agent name. -
populateInvocationAgentStates
RehydratesagentStates()andendOfAgents()from the current invocation's history when this invocation is resumable. For each event carrying agent-state information, sets the authoring agent's checkpoint; for a non-workflow author that already produced content, seeds an empty state so it is treated as mid-run. -
events
@Experimental public com.google.common.collect.ImmutableList<Event> events(boolean currentInvocation, boolean currentBranch) Returns the current session's events, optionally filtered to the current invocation and/or the current branch. Reads the in-memorySession.events()list, whichBaseSessionService.appendEvent(Session, Event)keeps in sync. Anull-branch event is visible on any branch.- Parameters:
currentInvocation- whether to filter to events from this invocation.currentBranch- whether to filter to events on this branch (or with no branch).
-
shouldPauseInvocation
Returns whether to pause the invocation right after this event: it is resumable and the event carries a long-running function call, including a syntheticadk_request_confirmationHITL request. Pausing, unlike ending, leaves the invocation resumable. -
equals
-
hashCode
-
isResumable().