Class BlackboardPlanner

java.lang.Object
dev.langchain4j.agentic.patterns.blackboard.BlackboardPlanner
All Implemented Interfaces:
Planner

public class BlackboardPlanner extends Object implements Planner
A blackboard planner that activates agents based on data availability in the shared scope.

Agents are knowledge sources that post partial results to the AgenticScope (the blackboard). After each agent completes, the planner inspects the blackboard and activates whichever single agent can contribute next. When multiple agents are ready, a ConflictResolutionStrategy determines which one fires; if no strategy is provided, declaration order is used.

The planner needs a goal to know when the work is over. The goal is either the goal predicate passed to the constructor, or, when none is given, the output key of the planner agent: the goal is then considered reached once that key is present in the scope. A blackboard without an output key has no goal and no reason to run, so configuring neither is rejected with an AgenticSystemConfigurationException.

The planner terminates successfully when:

  • The goal predicate is satisfied (by default, when the planner's outputKey is present in scope)
  • No agent can fire (quiescence)
If the maximum number of invocations is reached before the goal is satisfied, the planner throws an IllegalStateException.
  • Constructor Details

  • Method Details

    • init

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

      public Action firstAction(PlanningContext planningContext)
      Description copied from interface: Planner
      Returns the first action to execute when the planner starts (or resumes). Defaults to delegating to Planner.nextAction(PlanningContext).
      Specified by:
      firstAction in interface Planner
      Parameters:
      planningContext - the current planning context
      Returns:
      the first action to execute
    • nextAction

      public Action nextAction(PlanningContext planningContext)
      Description copied from interface: Planner
      Determines the next action to execute based on the result of the previous agent invocation.
      Specified by:
      nextAction in interface Planner
      Parameters:
      planningContext - the current planning context, including the previous agent's result
      Returns:
      the next action to execute
    • executionState

      public Map<String,Object> executionState()
      The agents that have to run, which are the ones whose inputs changed since they fired and the one selected for the current step, which did not complete, and the invocations made by the agents that completed: the selected one is counted again when it is selected again.
      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)
      Description copied from interface: Planner
      Restores the planner's execution state from a previously saved map. Called by the execution loop before Planner.firstAction(PlanningContext) when recovering from a persisted scope.

      The state restored can be the one of a planner whose agents had all completed: its completion is recorded with its result only when that result can be read back from a saved scope. A planner that computes its result itself then has to return it from Planner.firstAction(PlanningContext) with Planner.done(Object), since an action calling agents that all completed is completed by the execution loop without a result.

      Specified by:
      restoreExecutionState in interface Planner
      Parameters:
      state - the previously saved execution state
    • topology

      public AgenticSystemTopology topology()
      Description copied from interface: Planner
      Returns the topology of the agentic system managed by this planner.
      Specified by:
      topology in interface Planner
      Returns:
      the topology (defaults to AgenticSystemTopology.SEQUENCE)