Class InvocationContext

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

public class InvocationContext extends Object
The context for an agent invocation.
  • Constructor Details

  • Method Details

    • create

      @InlineMe(replacement="InvocationContext.builder().sessionService(sessionService).artifactService(artifactService).invocationId(invocationId).agent(agent).session(session).userContent(Optional.ofNullable(userContent)).runConfig(runConfig).build()", imports={"com.google.adk.agents.InvocationContext","java.util.Optional"}) @Deprecated(forRemoval=true) public static InvocationContext create(BaseSessionService sessionService, BaseArtifactService artifactService, String invocationId, BaseAgent agent, Session session, com.google.genai.types.Content userContent, RunConfig runConfig)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use builder() instead.
    • create

      @Deprecated(forRemoval=true) public static InvocationContext create(BaseSessionService sessionService, BaseArtifactService artifactService, BaseAgent agent, Session session, LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use builder() instead.
    • builder

      public static InvocationContext.Builder builder()
      Returns a new InvocationContext.Builder for creating InvocationContext instances.
    • toBuilder

      public InvocationContext.Builder toBuilder()
      Returns a InvocationContext.Builder initialized with the values of this instance.
    • copyOf

      @Deprecated(forRemoval=true) public static InvocationContext copyOf(InvocationContext other)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use other.toBuilder().build() instead.
      Creates a shallow copy of the given InvocationContext.
    • sessionService

      public BaseSessionService sessionService()
      Returns the session service for managing session state.
    • artifactService

      public BaseArtifactService artifactService()
      Returns the artifact service for persisting artifacts.
    • memoryService

      public BaseMemoryService memoryService()
      Returns the memory service for accessing agent memory.
    • pluginManager

      public Plugin pluginManager()
      Returns the plugin manager for accessing tools and plugins.
    • activeStreamingTools

      public Map<String, ActiveStreamingTool> activeStreamingTools()
      Returns a map of tool call IDs to active streaming tools for the current invocation.
    • liveRequestQueue

      public Optional<LiveRequestQueue> liveRequestQueue()
      Returns the queue for managing live requests, if available for this invocation.
    • invocationId

      public String invocationId()
      Returns the unique ID for this invocation.
    • branch

      public void branch(@Nullable String branch)
      Sets the [branch] ID for the current invocation. A branch represents a fork in the conversation history.
    • branch

      public Optional<String> branch()
      Returns the branch ID for the current invocation, if one is set. A branch represents a fork in the conversation history.
    • agent

      public BaseAgent agent()
      Returns the agent being invoked.
    • agent

      @Deprecated(forRemoval=true) public void agent(BaseAgent agent)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the [agent] being invoked. This is useful when delegating to a sub-agent.
    • session

      public Session session()
      Returns the session associated with this invocation.
    • userContent

      public Optional<com.google.genai.types.Content> userContent()
      Returns the user content that triggered this invocation, if any.
    • runConfig

      public RunConfig runConfig()
      Returns the configuration for the current agent run.
    • callbackContextData

      public Map<String,Object> callbackContextData()
      Returns a map for storing temporary context data that can be shared between different parts of the invocation (e.g., before/on/after model callbacks).
    • endInvocation

      public boolean endInvocation()
      Returns whether this invocation should be ended, e.g., due to reaching a terminal state or error.
    • setEndInvocation

      public void setEndInvocation(boolean endInvocation)
      Sets whether this invocation should be ended.
    • appName

      public String appName()
      Returns the application name associated with the session.
    • userId

      public String userId()
      Returns the user ID associated with the session.
    • newInvocationContextId

      public static String newInvocationContextId()
      Generates a new unique ID for an invocation context.
    • incrementLlmCallsCount

      public void incrementLlmCallsCount() throws LlmCallsLimitExceededException
      Increments the count of LLM calls made during this invocation and throws an exception if the limit defined in RunConfig is exceeded.
      Throws:
      LlmCallsLimitExceededException - if the call limit is exceeded
    • eventsCompactionConfig

      public Optional<EventsCompactionConfig> eventsCompactionConfig()
      Returns the events compaction configuration for the current agent run.
    • contextCacheConfig

      public Optional<ContextCacheConfig> contextCacheConfig()
      Returns the context cache configuration for the current agent run.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object