Class P2PPlanner

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

public final class P2PPlanner extends Object implements Planner
A peer-to-peer planner where agents activate dynamically as their input dependencies become available in session state.

Key behaviors:

  • Multiple agents can activate in parallel when their inputs are satisfied
  • When an agent produces output, other agents whose inputs are now satisfied activate
  • Agents can re-execute when their inputs change (iterative refinement)
  • Terminates on maxInvocations or a custom exit condition

Example: Research collaboration where a critic's feedback causes hypothesis refinement:

  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
  • Constructor Details

    • P2PPlanner

      public P2PPlanner(List<AgentMetadata> metadata, int maxInvocations, BiPredicate<Map<String,Object>, Integer> exitCondition)
      Creates a P2P planner with a custom exit condition.
      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)
      Creates a P2P planner that exits only on maxInvocations.
  • Method Details

    • init

      public void init(PlanningContext context)
      Description copied from interface: Planner
      Initialize the planner with context and available agents. Called once before the planning loop starts.

      Default implementation is a no-op. Override to perform setup like building dependency graphs.

      Specified by:
      init in interface Planner
    • firstAction

      public io.reactivex.rxjava3.core.Single<PlannerAction> firstAction(PlanningContext context)
      Description copied from interface: Planner
      Select the first action to execute.
      Specified by:
      firstAction in interface Planner
    • nextAction

      public io.reactivex.rxjava3.core.Single<PlannerAction> nextAction(PlanningContext context)
      Description copied from interface: Planner
      Select the next action based on updated state and events.
      Specified by:
      nextAction in interface Planner