Class BDIPlanner
java.lang.Object
dev.langchain4j.agentic.patterns.bdi.BDIPlanner
- All Implemented Interfaces:
Planner
A Belief-Desire-Intention planner that maintains prioritized goals (
Desires) and
reactively switches between them as the AgenticScope evolves. On each step the planner
checks whether a strictly higher-priority desire has become achievable and, if so, preempts the
current intention and re-deliberates. Among desires with equal priority, the one declared first
in the list is selected (stable ordering).-
Constructor Summary
ConstructorsConstructorDescriptionBDIPlanner(List<Desire> desires) BDIPlanner(List<Desire> desires, int maxInvocations) -
Method Summary
Modifier and TypeMethodDescriptionThe progress of each desire in its intention, with the current one at the agent that was dispatched and did not complete, and the invocations made by the agents that completed: the dispatched one is counted again when it is dispatched again.firstAction(PlanningContext planningContext) Returns the first action to execute when the planner starts (or resumes).voidinit(InitPlanningContext initPlanningContext) nextAction(PlanningContext planningContext) Determines the next action to execute based on the result of the previous agent invocation.voidrestoreExecutionState(Map<String, Object> state) On crash recovery the framework callsfirstAction(PlanningContext), which deliberates again: the satisfied desires are skipped, and the selected one goes on from the agent of its intention that had not completed, so that the agents that completed before it are not invoked again.topology()Returns the topology of the agentic system managed by this planner.
-
Constructor Details
-
BDIPlanner
-
BDIPlanner
-
-
Method Details
-
topology
Description copied from interface:PlannerReturns the topology of the agentic system managed by this planner.- Specified by:
topologyin interfacePlanner- Returns:
- the topology (defaults to
AgenticSystemTopology.SEQUENCE)
-
init
-
firstAction
Description copied from interface:PlannerReturns the first action to execute when the planner starts (or resumes). Defaults to delegating toPlanner.nextAction(PlanningContext).- Specified by:
firstActionin interfacePlanner- Parameters:
planningContext- the current planning context- Returns:
- the first action to execute
-
nextAction
Description copied from interface:PlannerDetermines the next action to execute based on the result of the previous agent invocation.- Specified by:
nextActionin interfacePlanner- Parameters:
planningContext- the current planning context, including the previous agent's result- Returns:
- the next action to execute
-
executionState
The progress of each desire in its intention, with the current one at the agent that was dispatched and did not complete, and the invocations made by the agents that completed: the dispatched one is counted again when it is dispatched again.- Specified by:
executionStatein interfacePlanner- Returns:
- a map of state entries to persist, or an empty map if no state needs saving
-
restoreExecutionState
On crash recovery the framework callsfirstAction(PlanningContext), which deliberates again: the satisfied desires are skipped, and the selected one goes on from the agent of its intention that had not completed, so that the agents that completed before it are not invoked again.- Specified by:
restoreExecutionStatein interfacePlanner- Parameters:
state- the previously saved execution state
-