Class DecisionRouterPlanner.Builder

java.lang.Object
dev.langchain4j.agentic.patterns.decisionrouter.DecisionRouterPlanner.Builder
Enclosing class:
DecisionRouterPlanner

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

    • decisionModel

      public DecisionRouterPlanner.Builder decisionModel(DecisionModel decisionModel)
      Sets the decision model choosing the subagents to invoke. Mandatory.
    • activationThreshold

      public DecisionRouterPlanner.Builder activationThreshold(Double activationThreshold)
      Sets the minimum probability of "yes" for a subagent to be invoked, strictly between 0 and 1. The router then asks the decision model, for each subagent, whether it should handle the request, invokes in parallel all the subagents reaching this threshold, and returns a map from the name of each invoked subagent to its output, so the method of the router agent must return a Map.

      By default there is no activation threshold, and the router invokes only the subagent that the decision model considers the most probable.

    • choiceQuestion

      public DecisionRouterPlanner.Builder choiceQuestion(String choiceQuestion)
      Sets the question asked to choose among the subagents, which are its options, when the router has no activation threshold.

      It is a plain question rather than a template: all the subagents are the options of a single choice question, so there is nothing to insert into the question.

      Default value is "Which agent is best suited to handle this request?".

    • relevanceQuestionTemplate

      public DecisionRouterPlanner.Builder relevanceQuestionTemplate(PromptTemplate relevanceQuestionTemplate)
      Sets the template of the yes/no question asked for each subagent when the router has an activation threshold, 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).

      Default value is DecisionRouterPlanner.DEFAULT_RELEVANCE_QUESTION_TEMPLATE.

    • build

      public DecisionRouterPlanner build()
      When the router is invoked, before asking the decision model, it fails with an IllegalArgumentException if the router agent is not a typed agent interface with at least one argument to send to the decision model, or if it has an activation threshold and its method does not return a Map (or a ResultWithAgenticScope of a Map).
      Throws:
      IllegalArgumentException - if the decision model is null, if the activation threshold is not strictly between 0 and 1, if the choice question is blank, or if the relevance question template contains neither {{name}} nor {{description}} or uses other variables