# Class InvocationContext.Builder

java.lang.Object
com.google.adk.agents.InvocationContext.Builder

Enclosing class:
  `InvocationContext`

public static class InvocationContext.Builder extends Object
Builder for `InvocationContext`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `InvocationContext.Builder`
  `agent(BaseAgent agent)`
  Sets the agent being invoked.
  `InvocationContext.Builder`
  `artifactService(BaseArtifactService artifactService)`
  Sets the artifact service for persisting artifacts.
  `InvocationContext.Builder`
  `branch(@Nullable String branch)`
  Sets the branch ID for the invocation.
  `InvocationContext`
  `build()`
  Builds the `InvocationContext` instance.
  `InvocationContext.Builder`
  `callbackContextData(Map<String,Object> callbackContextData)`
  Sets the callback context data for the invocation.
  `InvocationContext.Builder`
  `contextCacheConfig(@Nullable ContextCacheConfig contextCacheConfig)`
  Sets the context cache configuration for the current agent run.
  `InvocationContext.Builder`
  `endInvocation(boolean endInvocation)`
  Sets whether this invocation should be ended.
  `InvocationContext.Builder`
  `eventsCompactionConfig(@Nullable EventsCompactionConfig eventsCompactionConfig)`
  Sets the events compaction configuration for the current agent run.
  `InvocationContext.Builder`
  `invocationId(String invocationId)`
  Sets the unique ID for the invocation.
  `InvocationContext.Builder`
  `liveRequestQueue(@Nullable LiveRequestQueue liveRequestQueue)`
  Sets the queue for managing live requests.
  `InvocationContext.Builder`
  `memoryService(BaseMemoryService memoryService)`
  Sets the memory service for accessing agent memory.
  `InvocationContext.Builder`
  `pluginManager(Plugin pluginManager)`
  Sets the plugin manager for accessing tools and plugins.
  `InvocationContext.Builder`
  `runConfig(RunConfig runConfig)`
  Sets the configuration for the current agent run.
  `InvocationContext.Builder`
  `session(Session session)`
  Sets the session associated with this invocation.
  `InvocationContext.Builder`
  `sessionService(BaseSessionService sessionService)`
  Sets the session service for managing session state.
  `InvocationContext.Builder`
  `userContent(@Nullable com.google.genai.types.Content userContent)`
  Sets the user content that triggered this invocation.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### sessionService

    @CanIgnoreReturnValue public InvocationContext.Builder sessionService(BaseSessionService sessionService)
    Sets the session service for managing session state.
    Parameters:
      `sessionService` - the session service to use; required.
    Returns:
      this builder instance for chaining.

  - ### artifactService

    @CanIgnoreReturnValue public InvocationContext.Builder artifactService(BaseArtifactService artifactService)
    Sets the artifact service for persisting artifacts.
    Parameters:
      `artifactService` - the artifact service to use; required.
    Returns:
      this builder instance for chaining.

  - ### memoryService

    @CanIgnoreReturnValue public InvocationContext.Builder memoryService(BaseMemoryService memoryService)
    Sets the memory service for accessing agent memory.
    Parameters:
      `memoryService` - the memory service to use.
    Returns:
      this builder instance for chaining.

  - ### pluginManager

    @CanIgnoreReturnValue public InvocationContext.Builder pluginManager(Plugin pluginManager)
    Sets the plugin manager for accessing tools and plugins.
    Parameters:
      `pluginManager` - the plugin manager to use.
    Returns:
      this builder instance for chaining.

  - ### liveRequestQueue

    @CanIgnoreReturnValue public InvocationContext.Builder liveRequestQueue(@Nullable LiveRequestQueue liveRequestQueue)
    Sets the queue for managing live requests.
    Parameters:
      `liveRequestQueue` - the queue for managing live requests.
    Returns:
      this builder instance for chaining.

  - ### branch

    @CanIgnoreReturnValue public InvocationContext.Builder branch(@Nullable String branch)
    Sets the branch ID for the invocation.
    Parameters:
      `branch` - the branch ID for the invocation.
    Returns:
      this builder instance for chaining.

  - ### invocationId

    @CanIgnoreReturnValue public InvocationContext.Builder invocationId(String invocationId)
    Sets the unique ID for the invocation.
    Parameters:
      `invocationId` - the unique ID for the invocation.
    Returns:
      this builder instance for chaining.

  - ### agent

    @CanIgnoreReturnValue public InvocationContext.Builder agent(BaseAgent agent)
    Sets the agent being invoked.
    Parameters:
      `agent` - the agent being invoked; required.
    Returns:
      this builder instance for chaining.

  - ### session

    @CanIgnoreReturnValue public InvocationContext.Builder session(Session session)
    Sets the session associated with this invocation.
    Parameters:
      `session` - the session associated with this invocation; required.
    Returns:
      this builder instance for chaining.

  - ### userContent

    @CanIgnoreReturnValue public InvocationContext.Builder userContent(@Nullable com.google.genai.types.Content userContent)
    Sets the user content that triggered this invocation.
    Parameters:
      `userContent` - the user content that triggered this invocation.
    Returns:
      this builder instance for chaining.

  - ### runConfig

    @CanIgnoreReturnValue public InvocationContext.Builder runConfig(RunConfig runConfig)
    Sets the configuration for the current agent run.
    Parameters:
      `runConfig` - the configuration for the current agent run.
    Returns:
      this builder instance for chaining.

  - ### endInvocation

    @CanIgnoreReturnValue public InvocationContext.Builder endInvocation(boolean endInvocation)
    Sets whether this invocation should be ended.
    Parameters:
      `endInvocation` - whether this invocation should be ended.
    Returns:
      this builder instance for chaining.

  - ### eventsCompactionConfig

    @CanIgnoreReturnValue public InvocationContext.Builder eventsCompactionConfig(@Nullable EventsCompactionConfig eventsCompactionConfig)
    Sets the events compaction configuration for the current agent run.
    Parameters:
      `eventsCompactionConfig` - the events compaction configuration.
    Returns:
      this builder instance for chaining.

  - ### contextCacheConfig

    @CanIgnoreReturnValue public InvocationContext.Builder contextCacheConfig(@Nullable ContextCacheConfig contextCacheConfig)
    Sets the context cache configuration for the current agent run.
    Parameters:
      `contextCacheConfig` - the context cache configuration.
    Returns:
      this builder instance for chaining.

  - ### callbackContextData

    @CanIgnoreReturnValue public InvocationContext.Builder callbackContextData(Map<String,Object> callbackContextData)
    Sets the callback context data for the invocation.
    Parameters:
      `callbackContextData` - the callback context data.
    Returns:
      this builder instance for chaining.

  - ### build

    public InvocationContext build()
    Builds the `InvocationContext` instance.
    Throws:
      `IllegalStateException` - if any required parameters are missing.