InvocationContext class

Mutable invocation context shared across agent execution steps.

Constructors

InvocationContext({BaseArtifactService? artifactService, required BaseSessionService sessionService, Object? memoryService, Object? credentialService, Object? contextCacheConfig, required String invocationId, String? branch, String? nodePath, String? isolationScope, required BaseAgent agent, Content? userContent, required Session session, Map<String, Map<String, Object?>>? agentStates, Map<String, bool>? endOfAgents, bool endInvocation = false, LiveRequestQueue? liveRequestQueue, Map<String, ActiveStreamingTool>? activeStreamingTools, Map<String, Future<void>>? activeNonBlockingToolTasks, List<Object?>? transcriptionCache, String? liveSessionResumptionHandle, List<Object?>? inputRealtimeCache, List<Object?>? outputRealtimeCache, RunConfig? runConfig, ResumabilityConfig? resumabilityConfig, EventsCompactionConfig? eventsCompactionConfig, AdkAbortSignal? abortSignal, bool tokenCompactionChecked = false, PluginManager? pluginManager, List<BaseTool>? canonicalToolsCache, Map<String, AuthCredential>? credentialByKey, Map<String, Object?>? callbackContextData, Map<String, Object?>? privateMetadata})
Creates an invocation context for a single run.

Properties

abortEventSynthesized ↔ bool
Whether an abort event has already been synthesized for this invocation.
getter/setter pair
abortSignal ↔ AdkAbortSignal?
Cooperative cancellation signal for this invocation.
getter/setter pair
activeNonBlockingToolTasks ↔ Map<String, Future<void>>?
Active background tasks executing non-blocking tools in Live mode.
getter/setter pair
activeStreamingTools ↔ Map<String, ActiveStreamingTool>?
Active streaming tool handles by function call ID.
getter/setter pair
agent ↔ BaseAgent
Active agent for this invocation.
getter/setter pair
agentStates ↔ Map<String, Map<String, Object?>>
Serialized agent states by agent name.
getter/setter pair
appName → String
The application name for this invocation.
no setter
artifactService ↔ BaseArtifactService?
Artifact service used for persistence and retrieval.
getter/setter pair
branch ↔ String?
Branch identifier for branched execution, if any.
getter/setter pair
callbackContextData ↔ Map<String, Object?>
Shared invocation-scoped scratch data for flow/runner coordination.
getter/setter pair
canonicalToolsCache ↔ List<BaseTool>?
Cached canonical tool set, if computed.
getter/setter pair
contextCacheConfig ↔ Object?
Opaque context-cache configuration payload.
getter/setter pair
credentialByKey ↔ Map<String, AuthCredential>
Resolved credentials for this invocation keyed by auth credential key.
getter/setter pair
credentialService ↔ Object?
Credential service used for auth token persistence.
getter/setter pair
endInvocation ↔ bool
Whether the overall invocation has ended.
getter/setter pair
endOfAgents ↔ Map<String, bool>
Per-agent completion markers for resumable flows.
getter/setter pair
eventsCompactionConfig ↔ EventsCompactionConfig?
Event compaction settings for this invocation.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
inputRealtimeCache ↔ List<Object?>?
Buffered realtime input chunks.
getter/setter pair
invocationId ↔ String
Invocation identifier.
getter/setter pair
isAborted → bool
Whether this invocation has been cancelled.
no setter
isolationScope ↔ String?
Internal logical scope tag for filtering task-agent conversation views.
getter/setter pair
isResumable → bool
Whether resumable execution is enabled.
no setter
liveRequestQueue ↔ LiveRequestQueue?
Queue used by live-mode request handling.
getter/setter pair
liveSessionResumptionHandle ↔ String?
Opaque live-session resumption handle.
getter/setter pair
memoryService ↔ Object?
Memory service backing long-term memory APIs.
getter/setter pair
nodePath ↔ String?
Hierarchical node path in the workflow graph, if any.
getter/setter pair
outputRealtimeCache ↔ List<Object?>?
Buffered realtime output chunks.
getter/setter pair
pluginManager ↔ PluginManager
Plugin manager used throughout execution.
getter/setter pair
privateMetadata ↔ Map<String, Object?>
Invocation-scoped private metadata cache shared across context copies.
getter/setter pair
resumabilityConfig ↔ ResumabilityConfig?
Resumability policy for this invocation.
getter/setter pair
runConfig ↔ RunConfig?
Run configuration options.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
session ↔ Session
Backing session object.
getter/setter pair
sessionService ↔ BaseSessionService
Session service used for session reads and writes.
getter/setter pair
tokenCompactionChecked ↔ bool
Whether token compaction checks already ran.
getter/setter pair
transcriptionCache ↔ List<Object?>?
Cached transcription payloads across realtime turns.
getter/setter pair
userContent ↔ Content?
User-provided content for the current turn.
getter/setter pair
userId → String
The user ID for this invocation.
no setter

Methods

abort([Object? reason]) → void
Requests cancellation of this invocation.
addEventsToMemory({required List<Event> events, String? sessionId, Map<String, Object?>? customMetadata}) → Future<void>
Adds events to memory for this or another sessionId.
addMemory({required List<MemoryEntry> memories, Map<String, Object?>? customMetadata}) → Future<void>
Adds explicit memories to long-term memory.
addSessionToMemory() → Future<void>
Adds the current session transcript to memory.
agentStateKey(String agentName) → String
Returns the key used to store agent state for agentName.
copyWith({BaseAgent? agent, String? branch, Object? nodePath = _sentinel, Object? isolationScope = _sentinel, Content? userContent, String? invocationId, RunConfig? runConfig, AdkAbortSignal? abortSignal}) → InvocationContext
Creates a shallow-cloned context with selected overrides.
deleteArtifact({required String filename, String? sessionId}) → Future<void>
Deletes artifact filename from storage.
findMatchingFunctionCall(Event functionResponseEvent) → Event?
Finds the function-call event that matches functionResponseEvent.
getArtifactVersion({required String filename, String? sessionId, int? version}) → Future<ArtifactVersion?>
Returns metadata for artifact filename and optional version.
getEvents({bool currentInvocation = false, bool currentBranch = false}) → List<Event>
Returns events filtered by invocation and/or branch scopes.
incrementLlmCallCount() → void
Increments the LLM call counter and enforces RunConfig.maxLlmCalls.
listArtifacts({String? sessionId}) → Future<List<String>>
Lists artifact filenames for this invocation session.
listArtifactVersions({required String filename, String? sessionId}) → Future<List<int>>
Lists available versions for artifact filename.
loadArtifact({required String filename, String? sessionId, int? version}) → Future<Part?>
Loads an artifact filename and optional version.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
populateInvocationAgentStates() → void
Rebuilds in-memory agent state from current-invocation events.
resetSubAgentStates(String agentName) → void
Clears cached states for all descendants of agentName.
saveArtifact({required String filename, required Part artifact, String? sessionId, Map<String, Object?>? customMetadata}) → Future<int>
Saves an artifact to filename and returns its version.
searchMemory({required String query}) → Future<SearchMemoryResponse>
Searches memory with query.
setAgentState(String agentName, {BaseAgentState? agentState, bool endOfAgent = false}) → void
Sets or clears serialized state for agentName.
shouldPauseInvocation(Event event) → bool
Whether event should pause resumable invocation execution.
stampEventBranchContext(Event event) → void
Stamps the event with the branch and isolation scope of its matching function call.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited