# Class CallbackContext

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

Direct Known Subclasses:
  `ToolContext`

public class CallbackContext extends ReadonlyContext
The context of various callbacks for an agent invocation.

- ## Field Summary

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

  ### Fields inherited from class ReadonlyContext

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CallbackContext(InvocationContext invocationContext, EventActions eventActions)`
  Initializes callback context.
  `CallbackContext(InvocationContext invocationContext, EventActions eventActions, String eventId)`
  Initializes callback context.

- ## Method Summary

  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, toString, wait, wait, wait`

- ## Field Details

  - ### eventActions

    protected EventActions eventActions

- ## Constructor Details

  - ### CallbackContext

    public CallbackContext(InvocationContext invocationContext, EventActions eventActions)
    Initializes callback context.
    Parameters:
      `invocationContext` - Current invocation context.
      `eventActions` - Callback event actions.

  - ### CallbackContext

    public CallbackContext(InvocationContext invocationContext, EventActions eventActions, String eventId)
    Initializes callback context.
    Parameters:
      `invocationContext` - Current invocation context.
      `eventActions` - Callback event actions.
      `eventId` - The ID of the event associated with this context.

- ## Method Details

  - ### state

    public State state()
    Returns the delta-aware state of the current callback.
    Overrides:
      `state` in class `ReadonlyContext`

  - ### eventActions

    public EventActions eventActions()
    Returns the EventActions associated with this context.

  - ### eventId

    public String eventId()
    Returns the ID of the event associated with this context.

  - ### listArtifacts

    public io.reactivex.rxjava3.core.Single<List<String>> listArtifacts()
    Lists the filenames of the artifacts attached to the current session.
    Returns:
      the list of artifact filenames

  - ### loadArtifact

    public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename)
    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 `Completable` that completes when the artifact is saved.
    Throws:
      `IllegalStateException` - if the artifact service is not initialized.