Context
Execution context passed to agent callbacks, model callbacks, tools, and workflow nodes during an invocation.
Provides read access to invocation metadata and session state, along with methods to record state deltas, artifacts, and control-flow signals. Tool-specific operations such as requestConfirmation require a functionCallId, which is only populated during a tool call. The node-only members (such as output and routes) throw IllegalStateException unless this context was created for a workflow node; a callback, model-callback, or tool context is not a node activation and so has none of them.
A context is created in one of two ways: the public constructor is used for callbacks and tools, while the internal constructor is used for workflow node activations. Only the internal constructor populates node execution state (such as node and parent); contexts created with the public constructor leave that state empty, causing node-only members to throw.
CallbackContext and com.google.adk.kt.tools.ToolContext are thin subclasses kept for backward compatibility. Prefer Context in new code.
This class is open only so those two subclasses can exist as distinct JVM types that Java callers can reference. Every member is final so subclasses only forward constructor arguments without changing behavior.
Parameters
The tool confirmation of the current tool call.
Inheritors
Constructors
Properties
The event actions for the current context, holding state deltas and control-flow signals to be attached to emitted events.
The ArtifactService instance.
1-based attempt number, which a retry increments. 1 off-graph.
Per-invocation scratch data; see ContextFrameworkData.callbackContextData.
The readonly invocation context.
The same EventActions instance as actions, under the property name used by callbacks.
The author stamped on events this node emits.
The unique ID of the function call.
Whether an output has been produced, by this node or by a useAsOutput delegate.
Interrupt IDs this node activation is waiting on.
The unique ID of this invocation.
Every LiveRequest the live run takes off its queue, caller input and tool answers alike, including this tool's own, from when this flow is collected. Each collection gets its own buffered copy, which ends when the queue closes, the run ends, or this call's stream ends or is stopped. It is empty unless collected while the Flow a streaming tool returns in a live run is running, so callbacks and workflow nodes always see it empty.
The MemoryService instance.
The node this context is an activation of.
This activation's path: name@runId segments joined by /, rooted at the outermost node.
The context of the node that scheduled this one, or null at the root or off-graph.
Answers to this node's interrupts, keyed by interrupt id. Empty off-graph, except in a tool run by a tool node, which gets the node's answers so the rerun tool can read the answer to its own request.
The routes this node selected, read by the scheduler to pick the outgoing edges.
This activation's id within its node, counting from "1". It is a string because it forms the name@runId segment of a node path. "1" off-graph.
The user's answer to the current tool call's, or node run's, confirmation request.
The user content that this invocation is processing.
Functions
Triggers memory generation for the current session.
Requests the current LLM agent to stop after the current step completes.
Returns the credential the app sent back for authConfig, or null if there is none yet. It is read from state under the config's temp: key, then under its plain key, skipping a malformed value. When authConfig has an OAuth2 raw credential, its client ID and secret replace the stored ones; an OAuth2 authorization code is returned as is, not exchanged for a token.
Lists the filenames of the artifacts attached to the current session. Returns an empty list if no artifact service is configured.
Loads an artifact attached to the current session by name. Returns null if no artifact service is configured or the artifact is not found.
Merges the given event actions into the current event actions, replacing actions with the merged result, after checking their state delta against the state schema in force here, as updateState does. Any reference to actions taken before the merge will not receive subsequent writes.
Requests confirmation for the current tool call. Only a tool call has a functionCallId, so this can only be called in a tool context.
Asks the app for the credential authConfig describes: when the model called the tool on a turn-based run, the next event carries a sign-in request for it. A tool re-run after the app answers asks for nothing, so a tool still without a credential reports that to the model rather than asking again. Only a tool call has a functionCallId, so this can only be called in a tool context.
Sets this node's output to value's JSON form under T's serializer, or to a Content as it is, so a successor typed T reads it back, live and after a session reload. Can be called at most once per activation, and drops value if runNode already delegated output to a child with useAsOutput. Use it from a custom node for a typed value, since emitting that value directly fails the node.
Records a state change in actions stateDelta (copy-on-write) so it appears in state and flushes on the next event. State.TEMP_PREFIX keys are never stored. Under a node's state schema, a key without a colon must be declared and its value must fit and have a JSON form with finite numbers, unless the value is State.REMOVED; the checked value is stored in the JSON form a reloaded session reads back, and a typed credential stays typed.