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, 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, List<Object?>? transcriptionCache, String? liveSessionResumptionHandle, List<Object?>? inputRealtimeCache, List<Object?>? outputRealtimeCache, RunConfig? runConfig, ResumabilityConfig? resumabilityConfig, EventsCompactionConfig? eventsCompactionConfig, bool tokenCompactionChecked = false, PluginManager? pluginManager, List<BaseTool>? canonicalToolsCache})
Creates an invocation context for a single run.

Properties

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
canonicalToolsCache List<BaseTool>?
Cached canonical tool set, if computed.
getter/setter pair
contextCacheConfig Object?
Opaque context-cache configuration payload.
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
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
outputRealtimeCache List<Object?>?
Buffered realtime output chunks.
getter/setter pair
pluginManager PluginManager
Plugin manager used throughout execution.
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

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.
copyWith({BaseAgent? agent, String? branch, Content? userContent, String? invocationId, RunConfig? runConfig}) 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.
toString() String
A string representation of this object.
inherited

Operators

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