类:SequentialAgent

All Implemented Interfaces:
Node

public class SequentialAgent extends BaseAgent
一个依次运行其子代理的代理程序。

与……的组合(或搭配) LlmAgents: a SequentialAgent 不会将控制权返回给父进程(或父对象)。 LlmAgent将其作为根节点(root node)或被传输给代理的节点(agent node),并在此节点上放置任何后续操作(follow-up actions)。 LlmAgent 作为下一个“成员”(即下一个被处理的元素),上游系统会通过相应的渠道进行数据发布。 outputKey 以及 通过下游读取(data) {key} 其指令中的占位符(placeholders in its instruction):

var draft =
    LlmAgent.builder()
        .name("draft")
        .model("gemini-flash-latest")
        .instruction("Draft a summary.")
        .outputKey("draft")
        .build();
var reviewer =
    LlmAgent.builder()
        .name("reviewer")
        .model("gemini-flash-latest")
        .instruction("Polish the draft: {draft}")
        .build();
var pipeline =
    SequentialAgent.builder().name("pipeline").subAgents(draft, reviewer).build();
  • 方法详细信息(Method Details)

    • builder

      public static SequentialAgent.Builder builder()
    • runAsyncImpl

      protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext)
      按顺序运行子代理(sub-agents)。

      共有三种模式: 1. **支持恢复功能**:当该功能启用时,系统会快速将执行流程恢复到之前设置的检查点(即子代理的暂停位置);对于长时间运行的任务,系统会在暂停处继续执行。 2. **使用已弃用的“shim”机制**:虽然该机制仍能实现类似的功能,但恢复点会从历史记录中重新计算,且不会自动保存任何检查点数据。 3. **不使用任何恢复/暂停机制**:在这种情况下,子代理会按顺序依次执行。

      Specified by:
      runAsyncImpl in class BaseAgent
      Parameters:
      invocationContext - Invocation context.
      Returns:
      Flowable emitting events from sub-agents.
    • runLiveImpl

      protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext)
      在实时模式下,按顺序依次运行子代理(sub-agents)。
      Specified by:
      runLiveImpl in class BaseAgent
      Parameters:
      invocationContext - Invocation context.
      Returns:
      Flowable emitting events from sub-agents in live mode.
    • fromConfig

      public static SequentialAgent fromConfig(SequentialAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException
      根据配置创建一个 SequentialAgent 对象。
      Parameters:
      config - the agent configuration
      configAbsPath - The absolute path to the agent config file.
      Returns:
      the configured SequentialAgent
      Throws:
      ConfigAgentUtils.ConfigurationException - if the configuration is invalid