Class BDIPlanner

java.lang.Object
dev.langchain4j.agentic.patterns.bdi.BDIPlanner
All Implemented Interfaces:
Planner

public class BDIPlanner extends Object implements 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 Details

    • BDIPlanner

      public BDIPlanner(List<Desire> desires)
    • BDIPlanner

      public BDIPlanner(List<Desire> desires, int maxInvocations)
  • Method Details

    • topology

      public AgenticSystemTopology topology()
      Specified by:
      topology in interface Planner
    • init

      public void init(InitPlanningContext initPlanningContext)
      Specified by:
      init in interface Planner
    • firstAction

      public Action firstAction(PlanningContext planningContext)
      Specified by:
      firstAction in interface Planner
    • nextAction

      public Action nextAction(PlanningContext planningContext)
      Specified by:
      nextAction in interface Planner
    • executionState

      public Map<String,Object> executionState()
      Description copied from interface: Planner
      Returns the planner's current execution state as a map of serializable values. This state is persisted to the AgenticScope after each agent invocation, enabling the planner to resume from the correct position after a crash.

      The returned state must be such that, when passed to Planner.restoreExecutionState(Map) and Planner.firstAction(PlanningContext) is called, the planner produces the correct resume action.

      Stateless planners (e.g., parallel, conditional) can use the default empty implementation.

      Specified by:
      executionState in interface Planner
      Returns:
      a map of state entries to persist, or an empty map if no state needs saving
    • restoreExecutionState

      public void restoreExecutionState(Map<String,Object> state)
      Only invocationCounter is persisted. On crash recovery the framework calls firstAction(PlanningContext), which re-deliberates from scratch: satisfied desires are skipped, but the selected desire's intention restarts from its first agent — agents that already completed will run again. Intention agents must therefore be idempotent.
      Specified by:
      restoreExecutionState in interface Planner
      Parameters:
      state - the previously saved execution state