Class Runner

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

public class Runner extends Object
用于运行 GenAI Agents 的主要类。
  • 构造函数详细信息

  • 方法详细信息(Method Details)

    • builder

      public static Runner.Builder builder()
    • agent

      public BaseAgent agent()
    • node

      @Experimental public Optional<Node> node()
      返回该运行器所执行的工作流节点;当它执行代理树(agent tree)时,返回空值。当它执行某个具体工作流节点时,会返回该节点的相关信息。 agent() 返回一个 NodeViewAgent 它就代表了那个东西(或那个人)。
    • 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()
      关闭所有插件和代码执行器,并释放所有相关资源。
    • 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)
      以基于调用的方式运行代理程序。

      TODO:将此代码段作为主要的实现方案。

      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)
      运行代理程序,会恢复现有的调用(即继续执行之前已开始的操作),而不是启动一个新的调用。该调用的具体执行细节由相关系统或框架负责处理。 invocationId或者从函数返回的结果中获取(该结果是通过某种方式传递过来的)。 newMessage代理检查点(Agent checkpoints)会从历史记录中重新获取所需的数据;如果当前活跃的代理(active agent)已经完成了相应的操作,那么该操作会被视为“无操作”(no-op)。而工作流节点(workflow node)的根节点(root node)则会根据该调用事件(invocation events)来重新计算自己的执行进度——即使应用程序本身无法继续执行(即无法恢复运行状态)。
      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)
      使用提供的 `Session` 对象异步运行代理程序。
      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)
    • runLive

      public io.reactivex.rxjava3.core.Flowable<Event> runLive(String userId, String sessionId, LiveRequestQueue liveRequestQueue, RunConfig runConfig)
      检索会话信息,并以实时模式运行代理程序。
      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)
      检索会话信息,并以实时模式运行代理程序。
      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)
      以实时模式运行代理程序,并将生成的日志事件添加到会话记录中。
      Returns:
      stream of events from the agent.