Class DecisionSchedulerPlanner.Builder

java.lang.Object
dev.langchain4j.agentic.patterns.decisionscheduler.DecisionSchedulerPlanner.Builder
Enclosing class:
DecisionSchedulerPlanner

public static final class DecisionSchedulerPlanner.Builder extends Object
  • Method Details

    • decisionModel

      public DecisionSchedulerPlanner.Builder decisionModel(DecisionModel decisionModel)
      Sets the decision model scoring the subagents and judging whether the goal has been reached. Mandatory.
    • goal

      Sets the description of the goal, for instance "The reply answers every question of the customer's ticket". It is sent to the decision model in every question. Mandatory, and not blank.
    • goalThreshold

      public DecisionSchedulerPlanner.Builder goalThreshold(Double goalThreshold)
      Sets the minimum probability that the goal has been reached for the planner to stop. Mandatory, strictly between 0 and 1.
    • activationThreshold

      public DecisionSchedulerPlanner.Builder activationThreshold(Double activationThreshold)
      Sets the minimum score for the most useful subagent to be invoked: when no subagent reaches it the planner stops. The score goes from 0 (the lowest usefulness level) to 1 (the highest one): with the default levels, "USELESS" is 0, "MARGINAL" 1/3, "USEFUL" 2/3 and "ESSENTIAL" 1. Mandatory, strictly between 0 and 1.
    • maxInvocations

      public DecisionSchedulerPlanner.Builder maxInvocations(Integer maxInvocations)
      Sets the maximum number of subagent invocations, after which the planner stops with a warning, without asking the decision model again, or fails if the result has not been written yet. At least 1.

      Default value is 10.

    • goalQuestionTemplate

      public DecisionSchedulerPlanner.Builder goalQuestionTemplate(PromptTemplate goalQuestionTemplate)
      Sets the template of the yes/no question asking whether the goal has been reached, which can use the {{goal}} variable (the goal set with goal(String)).

      Default value is DecisionSchedulerPlanner.DEFAULT_GOAL_QUESTION_TEMPLATE.

    • usefulnessQuestionTemplate

      public DecisionSchedulerPlanner.Builder usefulnessQuestionTemplate(PromptTemplate usefulnessQuestionTemplate)
      Sets the template of the scale question asking how useful it would be to invoke a subagent now, which must contain the {{name}} or the {{description}} variable (the name and the description of the subagent, or its name when it has no description), and can use the {{goal}} variable.

      Default value is DecisionSchedulerPlanner.DEFAULT_USEFULNESS_QUESTION_TEMPLATE.

    • usefulnessLevels

      public DecisionSchedulerPlanner.Builder usefulnessLevels(List<String> usefulnessLevels)
      Sets the levels of the usefulness question, at least 2, from the lowest to the highest. The score of a subagent is the mean level of the answer scaled between 0 (the lowest level) and 1 (the highest one).

      Default value is DecisionSchedulerPlanner.DEFAULT_USEFULNESS_LEVELS.

    • excludedOutputKeys

      public DecisionSchedulerPlanner.Builder excludedOutputKeys(String... excludedOutputKeys)
      Sets the output keys of the subagents to leave out of the input of the decision model, for instance because they hold data that must not be sent to its provider. The subagents still read these outputs from the scope, but the decision model scores the subagents and judges the goal without seeing them, so only the outputs that these decisions do not need should be left out. A key left out is not sent even when it is also an argument of the planner agent. The output key of the planner agent cannot be left out, since the goal is judged on the result.

      By default no output key is left out.

    • build

      public DecisionSchedulerPlanner build()
      When the planner is initialized, at each invocation, it fails with an IllegalArgumentException if the planner agent is not a typed agent interface with at least one argument to send to the decision model, or if one of the output keys to leave out is not the output key of one of its subagents, or is the output key of the planner agent.
      Throws:
      IllegalArgumentException - if the decision model is null, if the goal is null or blank, if a threshold is not set or is not strictly between 0 and 1, if the maximum number of invocations is less than 1, if a question template uses other variables than its own or the usefulness question template contains neither {{name}} nor {{description}}, or if there are fewer than 2 usefulness levels