Class LoopAgent

All Implemented Interfaces:
Node

public class LoopAgent extends BaseAgent
一个代理程序,它会按顺序循环执行其下属的子代理程序。

循环会一直持续下去,直到某个子代理向上级报告问题(即“升级”该问题),或者直到达到预定的最大迭代次数(如果事先指定了最大迭代次数的话)。

与……的组合(或搭配) LlmAgents: a LoopAgent 不会将控制权重新转移回父进程(或父对象)。 LlmAgent. 为了对循环结果做出反应,请将相关代码放在此处。 LoopAgent 以及后续行动(或:后续措施)。 LlmAgent 就像一家人中的兄弟姐妹一样…… SequentialAgent循环子代理通过以下方式发布内容: outputKey 接下来的内容是通过(某种方式)读取的。 {key} 其指令中的占位符(placeholders in its instruction):

var refiner =
    LlmAgent.builder()
        .name("refiner")
        .model("gemini-flash-latest")
        .instruction("Refine: {draft?}")
        .outputKey("draft")
        .build();
var publisher =
    LlmAgent.builder()
        .name("publisher")
        .model("gemini-flash-latest")
        .instruction("Publish: {draft}")
        .build();
var loop =
    LoopAgent.builder().name("loop").subAgents(refiner).maxIterations(3).build();
var root = SequentialAgent.builder().name("root").subAgents(loop, publisher).build();
  • 方法详细信息(Method Details)

    • builder

      public static LoopAgent.Builder builder()
    • fromConfig

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

      protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext)
      描述内容复制自相关类: BaseAgent
      与特定代理(Agent)相关的异步逻辑(Agent-specific asynchronous logic)。
      Specified by:
      runAsyncImpl in class BaseAgent
      Parameters:
      invocationContext - Current invocation context.
      Returns:
      stream of agent-generated events.
    • runLiveImpl

      protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext)
      描述内容复制自相关类: BaseAgent
      与特定代理相关的同步逻辑(Agent-specific synchronous logic)。
      Specified by:
      runLiveImpl in class BaseAgent
      Parameters:
      invocationContext - Current invocation context.
      Returns:
      stream of agent-generated events.
    • maxIterations

      public @Nullable Integer maxIterations()