`Class ParallelAgent`

All Implemented Interfaces:
Node

public class ParallelAgent extends BaseAgent
这是一个 shell 代理程序,它能够以并行方式、并在隔离的环境中运行其下属代理程序(即子代理)。

这种方法适用于那些需要从多个角度或多次尝试来完成同一任务的场景,例如同时运行不同的算法,或生成多个结果供后续的评估人员进行审查。

与……的组合(或搭配) LlmAgents: a ParallelAgent 不会将控制权返回给父进程(或父对象)。 LlmAgent要执行“先扩散(fan-out)再聚合(aggregation)”的操作,需要将这两个步骤封装在一个容器(例如函数或方法)中。 SequentialAgent (用作根节点或转发给代理)。每个并行子代理都会通过相应的渠道进行数据发布。 outputKey 然后,聚合器通过(指定的方式)进行数据读取。 {key} 其指令中的占位符(placeholders in its instruction):

var contacts =
    LlmAgent.builder()
        .name("contacts")
        .model("gemini-flash-latest")
        .instruction("List contacts.")
        .outputKey("contacts")
        .build();
var schedule =
    LlmAgent.builder()
        .name("schedule")
        .model("gemini-flash-latest")
        .instruction("List schedule.")
        .outputKey("schedule")
        .build();
var writer =
    LlmAgent.builder()
        .name("writer")
        .model("gemini-flash-latest")
        .instruction("Write: contacts={contacts}, schedule={schedule}")
        .build();
var gather =
    ParallelAgent.builder().name("gather").subAgents(contacts, schedule).build();
var root = SequentialAgent.builder().name("root").subAgents(gather, writer).build();
  • 方法详细信息(Method Details)

    • builder

      public static ParallelAgent.Builder builder()
    • fromConfig

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

      protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext)
      并行运行子代理(sub-agents),并收集它们产生的事件数据。

      设置分支,并合并来自所有子代理的事件流。

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

      protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext)
      ParallelAgent 不支持该功能。
      Specified by:
      runLiveImpl in class BaseAgent
      Parameters:
      invocationContext - Invocation context.
      Returns:
      Flowable that always throws UnsupportedOperationException.