Class Context
java.lang.Object
com.google.adk.agents.ReadonlyContext
com.google.adk.agents.Context
- Direct Known Subclasses:
CallbackContext
The context passed to callbacks and tools during an invocation.
Agent and model callbacks receive a CallbackContext, and tools and tool callbacks a
ToolContext; both extend this class, so a helper that serves both,
or a function tool's toolContext parameter, can take a Context. requestConfirmation() needs a function call ID, which only a tool call has.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected EventActionsThe event actions that record this context's changes.Fields inherited from class ReadonlyContext
invocationContext -
Method Summary
Modifier and TypeMethodDescriptionactions()Returns the sameEventActionsaseventActions().Returns theEventActionsassociated with this context.eventId()Returns the ID of the event associated with this context, or null if there is none.Returns the ID of the function call that invoked the current tool, if any.voidfunctionCallId(@Nullable String functionCallId) Sets the ID of the function call that invoked the current tool, or clears it if null.Lists the filenames of the artifacts attached to the current session.io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename) Loads the latest version of an artifact from the service.io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename, int version) Loads a specific version of an artifact from the service.voidRequests confirmation for the current function call.voidrequestConfirmation(@Nullable String hint) Requests confirmation for the current function call.voidrequestConfirmation(@Nullable String hint, @Nullable Object payload) Requests confirmation for the current function call.io.reactivex.rxjava3.core.CompletablesaveArtifact(String filename, com.google.genai.types.Part artifact) Saves an artifact and records it as a delta for the current session.io.reactivex.rxjava3.core.Single<SearchMemoryResponse> searchMemory(String query) Searches the memory of the current user.state()Returns the delta-aware state of the current context.Returns the confirmation of the current tool call, if any.voidtoolConfirmation(@Nullable ToolConfirmation toolConfirmation) Sets the confirmation of the current tool call, or clears it if null.Methods inherited from class ReadonlyContext
agentName, branch, events, invocationContext, invocationId, sessionId, userContent, userIdModifier and TypeMethodDescriptionReturns the name of the agent currently running.branch()Returns the branch of the current invocation, if present.events()Returns an unmodifiable view of the events of the session.Returns the invocation context.Returns the ID of the current invocation.Returns the session ID.Optional<com.google.genai.types.Content> Returns the user content that initiated this invocation.userId()Returns the user ID.
-
Field Details
-
eventActions
The event actions that record this context's changes.
-
-
Method Details
-
state
Returns the delta-aware state of the current context.- Overrides:
statein classReadonlyContext
-
eventActions
Returns theEventActionsassociated with this context. -
actions
Returns the sameEventActionsaseventActions(). -
eventId
Returns the ID of the event associated with this context, or null if there is none. -
functionCallId
-
functionCallId
Sets the ID of the function call that invoked the current tool, or clears it if null. -
toolConfirmation
Returns the confirmation of the current tool call, if any. -
toolConfirmation
Sets the confirmation of the current tool call, or clears it if null. -
listArtifacts
-
loadArtifact
Loads the latest version of an artifact from the service. -
loadArtifact
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename, int version) Loads a specific version of an artifact from the service. -
saveArtifact
public io.reactivex.rxjava3.core.Completable saveArtifact(String filename, com.google.genai.types.Part artifact) Saves an artifact and records it as a delta for the current session.- Parameters:
filename- Artifact file name.artifact- Artifact content to save.- Returns:
- a
Completablethat completes when the artifact is saved. - Throws:
IllegalStateException- if the artifact service is not initialized.
-
requestConfirmation
Requests confirmation for the current function call.- Parameters:
hint- A hint to the user on how to confirm the tool call.payload- The payload used to confirm the tool call.- Throws:
IllegalStateException- if this context has no function call ID.
-
requestConfirmation
Requests confirmation for the current function call.- Parameters:
hint- A hint to the user on how to confirm the tool call.- Throws:
IllegalStateException- if this context has no function call ID.
-
requestConfirmation
public void requestConfirmation()Requests confirmation for the current function call.- Throws:
IllegalStateException- if this context has no function call ID.
-
searchMemory
Searches the memory of the current user.
-