Class Runner

java.lang.Object
com.google.adk.runner.Runner
Direct Known Subclasses:
FirestoreDatabaseRunner, InMemoryRunner

public class Runner extends Object
The main class for the GenAI Agents runner.
  • Constructor Details

  • Method Details

    • builder

      public static Runner.Builder builder()
    • agent

      public BaseAgent agent()
    • node

      @Experimental public Optional<Node> node()
      Returns the workflow node this runner runs, or empty when it runs an agent tree. When it runs a node, agent() returns a NodeViewAgent that stands in for it.
    • appName

      public String appName()
    • artifactService

      public BaseArtifactService artifactService()
    • sessionService

      public BaseSessionService sessionService()
    • memoryService

      public @Nullable BaseMemoryService memoryService()
    • pluginManager

      public PluginManager pluginManager()
    • close

      public io.reactivex.rxjava3.core.Completable close()
      Closes all plugins, code executors, and releases any resources.
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(String userId, String sessionId, com.google.genai.types.Content newMessage, RunConfig runConfig)
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(String userId, String sessionId, com.google.genai.types.Content newMessage, RunConfig runConfig, @Nullable Map<String,Object> stateDelta)
      Runs the agent with an invocation-based mode.

      TODO: make this the main implementation.

      Parameters:
      userId - The ID of the user for the session.
      sessionId - The ID of the session to run the agent in.
      newMessage - The new message from the user to process.
      runConfig - Configuration for the agent run.
      stateDelta - Optional map of state updates to merge into the session for this run.
      Returns:
      A Flowable stream of Event objects generated by the agent during execution.
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(SessionKey sessionKey, com.google.genai.types.Content newMessage, RunConfig runConfig, @Nullable Map<String,Object> stateDelta)
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(SessionKey sessionKey, com.google.genai.types.Content newMessage, RunConfig runConfig)
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(SessionKey sessionKey, com.google.genai.types.Content newMessage)
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(String userId, String sessionId, com.google.genai.types.Content newMessage)
    • runAsync

      @Experimental public io.reactivex.rxjava3.core.Flowable<Event> runAsync(String userId, String sessionId, @Nullable String invocationId, @Nullable com.google.genai.types.Content newMessage, RunConfig runConfig, @Nullable Map<String,Object> stateDelta)
      Runs the agent, resuming an existing invocation instead of starting a new one. The invocation is resolved from invocationId, or from a function response carried by newMessage; for a workflow node root, a plain message instead joins the invocation of a task that waits on the user. Agent checkpoints are rehydrated from history and an invocation whose active agent already finished resolves to a no-op, while a workflow node root rebuilds its progress from the invocation's events even when the app is not resumable.
      Parameters:
      userId - the user id of the session.
      sessionId - the session id.
      invocationId - the invocation to resume; may be null when it can be inferred from newMessage.
      newMessage - an optional message (typically a function response) to append before running.
      runConfig - the run configuration.
      stateDelta - optional state updates to merge into the session for this run.
      Returns:
      the events generated while resuming, or an empty stream when there is nothing to resume.
      Throws:
      IllegalStateException - if the app is not resumable and its root is an agent.
      IllegalArgumentException - if the invocation cannot be resolved.
    • runAsyncImpl

      protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(Session session, com.google.genai.types.Content newMessage, RunConfig runConfig, @Nullable Map<String,Object> stateDelta)
      Runs the agent asynchronously using a provided Session object.
      Parameters:
      session - The session to run the agent in.
      newMessage - The new message from the user to process.
      runConfig - Configuration for the agent run.
      stateDelta - Optional map of state updates to merge into the session for this run.
      Returns:
      A Flowable stream of Event objects generated by the agent during execution.
    • runLive

      public io.reactivex.rxjava3.core.Flowable<Event> runLive(Session session, LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      Runs the agent in live mode.

      Canceling the returned stream still runs plugin afterRun callbacks once the agent has stopped. They run on the canceling thread, and cancellation does not wait for an asynchronous afterRun to finish.

      Returns:
      stream of events from the agent.
    • runLive

      public io.reactivex.rxjava3.core.Flowable<Event> runLive(String userId, String sessionId, LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      Retrieves the session and runs the agent in live mode.

      Canceling the returned stream still runs plugin afterRun callbacks once the agent has stopped. They run on the canceling thread, and cancellation does not wait for an asynchronous afterRun to finish.

      Returns:
      stream of events from the agent.
      Throws:
      IllegalArgumentException - if the session is not found.
    • runLive

      public io.reactivex.rxjava3.core.Flowable<Event> runLive(SessionKey sessionKey, LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      Retrieves the session and runs the agent in live mode.

      Canceling the returned stream still runs plugin afterRun callbacks once the agent has stopped. They run on the canceling thread, and cancellation does not wait for an asynchronous afterRun to finish.

      Returns:
      stream of events from the agent.
      Throws:
      IllegalArgumentException - if the session is not found.
    • runLiveImpl

      protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(Session session, @Nullable LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      Runs the agent in live mode, appending generated events to the session.
      Returns:
      stream of events from the agent.