Class P2PPlanner
java.lang.Object
com.google.adk.planner.p2p.P2PPlanner
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionP2PPlanner(List<AgentMetadata> metadata, int maxInvocations) Creates a P2P planner that exits only on maxInvocations.P2PPlanner(List<AgentMetadata> metadata, int maxInvocations, BiPredicate<Map<String, Object>, Integer> exitCondition) Creates a P2P planner with a custom exit condition. -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Single<PlannerAction> firstAction(PlanningContext context) Select the first action to execute.voidinit(PlanningContext context) Initialize the planner with context and available agents.io.reactivex.rxjava3.core.Single<PlannerAction> nextAction(PlanningContext context) Select the next action based on updated state and events.
-
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 declarationsmaxInvocations- maximum total agent invocations before terminationexitCondition- predicate tested on (state, invocationCount); returns true to stop
-
P2PPlanner
Creates a P2P planner that exits only on maxInvocations.
-
-
Method Details
-
init
Description copied from interface:PlannerInitialize 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.
-
firstAction
Description copied from interface:PlannerSelect the first action to execute.- Specified by:
firstActionin interfacePlanner
-
nextAction
Description copied from interface:PlannerSelect the next action based on updated state and events.- Specified by:
nextActionin interfacePlanner
-