# Class ToolContext

java.lang.Object
com.google.adk.agents.ReadonlyContext
com.google.adk.agents.CallbackContext
com.google.adk.tools.ToolContext

public class ToolContext extends CallbackContext
ToolContext object provides a structured context for executing tools or functions.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `ToolContext.Builder`
  Builder for `ToolContext`.

- ## Field Summary

  ### Fields inherited from class CallbackContext

  `eventActions`
  Modifier and Type
  Field
  Description
  `protected EventActions`
  `eventActions`

  ### Fields inherited from class ReadonlyContext

  `invocationContext`
  Modifier and Type
  Field
  Description
  `protected final InvocationContext`
  `invocationContext`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `EventActions`
  `actions()`
  `static ToolContext.Builder`
  `builder(InvocationContext invocationContext)`
  `Optional<String>`
  `functionCallId()`
  `void`
  `functionCallId(String functionCallId)`
  `void`
  `requestConfirmation()`
  Requests confirmation for the given function call.
  `void`
  `requestConfirmation(@Nullable String hint)`
  Requests confirmation for the given function call.
  `void`
  `requestConfirmation(@Nullable String hint, @Nullable Object payload)`
  Requests confirmation for the given function call.
  `io.reactivex.rxjava3.core.Single<SearchMemoryResponse>`
  `searchMemory(String query)`
  Searches the memory of the current user.
  `void`
  `setActions(EventActions actions)`
  `ToolContext.Builder`
  `toBuilder()`
  `Optional<ToolConfirmation>`
  `toolConfirmation()`
  `void`
  `toolConfirmation(ToolConfirmation toolConfirmation)`
  `String`
  `toString()`

  ### Methods inherited from class CallbackContext

  `eventActions, eventId, listArtifacts, loadArtifact, loadArtifact, saveArtifact, state`
  Modifier and Type
  Method
  Description
  `EventActions`
  `eventActions()`
  Returns the EventActions associated with this context.
  `String`
  `eventId()`
  Returns the ID of the event associated with this context.
  `io.reactivex.rxjava3.core.Single<List<String>>`
  `listArtifacts()`
  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.
  `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.
  `State`
  `state()`
  Returns the delta-aware state of the current callback.

  ### Methods inherited from class ReadonlyContext

  `agentName, branch, events, invocationContext, invocationId, sessionId, userContent, userId`
  Modifier and Type
  Method
  Description
  `String`
  `agentName()`
  Returns the name of the agent currently running.
  `Optional<String>`
  `branch()`
  Returns the branch of the current invocation, if present.
  `List<Event>`
  `events()`
  Returns an unmodifiable view of the events of the session.
  `InvocationContext`
  `invocationContext()`
  Returns the invocation context.
  `String`
  `invocationId()`
  Returns the ID of the current invocation.
  `String`
  `sessionId()`
  Returns the session ID.
  `Optional<com.google.genai.types.Content>`
  `userContent()`
  Returns the user content that initiated this invocation.
  `String`
  `userId()`
  Returns the user ID.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### actions

    public EventActions actions()

  - ### setActions

    public void setActions(EventActions actions)

  - ### functionCallId

    public Optional<String> functionCallId()

  - ### functionCallId

    public void functionCallId(String functionCallId)

  - ### toolConfirmation

    public Optional<ToolConfirmation> toolConfirmation()

  - ### toolConfirmation

    public void toolConfirmation(ToolConfirmation toolConfirmation)

  - ### requestConfirmation

    public void requestConfirmation(@Nullable String hint, @Nullable Object payload)
    Requests confirmation for the given 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.

  - ### requestConfirmation

    public void requestConfirmation(@Nullable String hint)
    Requests confirmation for the given function call.
    Parameters:
      `hint` - A hint to the user on how to confirm the tool call.

  - ### requestConfirmation

    public void requestConfirmation()
    Requests confirmation for the given function call.

  - ### searchMemory

    public io.reactivex.rxjava3.core.Single<SearchMemoryResponse> searchMemory(String query)
    Searches the memory of the current user.

  - ### builder

    public static ToolContext.Builder builder(InvocationContext invocationContext)

  - ### toBuilder

    public ToolContext.Builder toBuilder()

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`