Class P2PPlanner

java.lang.Object
com.google.adk.planner.p2p.P2PPlanner
All Implemented Interfaces:
Planner

public final class P2PPlanner extends Object implements Planner
这是一个基于点对点(P2P)技术的规划工具:当代理所需的输入数据在会话状态中变得可用时,这些代理会自动被激活并开始执行相应的任务。

关键行为:

  • 当多个代理的输入条件得到满足时,它们可以同时被激活(即并行运行)。
  • 当一个代理生成输出后,那些输入条件已经得到满足的其他代理就会被激活。
  • 当代理的输入数据发生变化时,它们可以重新执行相应的操作(即进行迭代式的优化或调整)。
  • 当调用次数达到最大值(maxInvocations)或满足自定义的退出条件时,程序将终止。

示例:一种研究合作模式——在这种模式下,评论者的反馈有助于完善研究假设。

  LiteratureAgent (needs: topic) → researchFindings
  HypothesisAgent (needs: topic, researchFindings) → hypothesis
  CriticAgent (needs: topic, hypothesis) → critique
  ScorerAgent (needs: topic, hypothesis, critique) → score
  Exit when: score >= 0.85
  • 构造函数详细信息

    • P2PPlanner

      public P2PPlanner(List<AgentMetadata> metadata, int maxInvocations, BiPredicate<Map<String,Object>, Integer> exitCondition)
      创建一个具有自定义退出条件的 P2P 规划器(P2P Planner)。
      Parameters:
      metadata - agent input/output declarations
      maxInvocations - maximum total agent invocations before termination
      exitCondition - predicate tested on (state, invocationCount); returns true to stop
    • P2PPlanner

      public P2PPlanner(List<AgentMetadata> metadata, int maxInvocations)
      创建一个 P2P 规划器(P2P Planner),该规划器仅在达到最大调用次数(maxInvocations)时才会停止运行。
  • 方法详细信息(Method Details)

    • init

      public void init(PlanningContext context)
      描述内容复制自接口文档: Planner
      使用上下文信息及可用的代理来初始化规划器。该函数仅在规划循环开始之前被调用一次。

      默认实现是一个空操作(即什么都不做)。如果需要执行某些设置工作(例如构建依赖关系图),请覆盖该实现。

      Specified by:
      init in interface Planner
    • firstAction

      public io.reactivex.rxjava3.core.Single<PlannerAction> firstAction(PlanningContext context)
      描述内容复制自接口文档: Planner
      请选择要执行的第一个操作。
      Specified by:
      firstAction in interface Planner
    • nextAction

      public io.reactivex.rxjava3.core.Single<PlannerAction> nextAction(PlanningContext context)
      描述内容复制自接口文档: Planner
      根据更新后的状态和事件,选择下一步要执行的操作。
      Specified by:
      nextAction in interface Planner