# Class ReadonlyContext

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

Direct Known Subclasses:
  `CallbackContext`

public class ReadonlyContext extends Object
Provides read-only access to the context of an agent run.

- ## Field Summary

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ReadonlyContext(InvocationContext invocationContext)`

- ## Method Summary

  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.
  `Map<String,Object>`
  `state()`
  Returns an unmodifiable view of the state of the session.
  `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

  - ### invocationContext

    protected final InvocationContext invocationContext

- ## Constructor Details

  - ### ReadonlyContext

    public ReadonlyContext(InvocationContext invocationContext)

- ## Method Details

  - ### userContent

    public Optional<com.google.genai.types.Content> userContent()
    Returns the user content that initiated this invocation.

  - ### invocationContext

    public InvocationContext invocationContext()
    Returns the invocation context.

  - ### invocationId

    public String invocationId()
    Returns the ID of the current invocation.

  - ### branch

    public Optional<String> branch()
    Returns the branch of the current invocation, if present.

  - ### agentName

    public String agentName()
    Returns the name of the agent currently running.

  - ### userId

    public String userId()
    Returns the user ID.

  - ### sessionId

    public String sessionId()
    Returns the session ID.

  - ### events

    public List<Event> events()
    Returns an unmodifiable view of the events of the session.

    Warning: This is a live view, not a snapshot.

  - ### state

    public Map<String,Object> state()
    Returns an unmodifiable view of the state of the session.

    Warning: This is a live view, not a snapshot.