Class DecisionRouterPlanner.Builder
java.lang.Object
dev.langchain4j.agentic.patterns.decisionrouter.DecisionRouterPlanner.Builder
- Enclosing class:
DecisionRouterPlanner
-
Method Summary
Modifier and TypeMethodDescriptionactivationThreshold(Double activationThreshold) Sets the minimum probability of "yes" for a subagent to be invoked, strictly between 0 and 1.build()When the router is invoked, before asking the decision model, it fails with anIllegalArgumentExceptionif 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 aMap(or aResultWithAgenticScopeof aMap).choiceQuestion(String choiceQuestion) Sets the question asked to choose among the subagents, which are its options, when the router has no activation threshold.decisionModel(DecisionModel decisionModel) Sets the decision model choosing the subagents to invoke.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).
-
Method Details
-
decisionModel
Sets the decision model choosing the subagents to invoke. Mandatory. -
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 aMap.By default there is no activation threshold, and the router invokes only the subagent that the decision model considers the most probable.
-
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
When the router is invoked, before asking the decision model, it fails with anIllegalArgumentExceptionif 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 aMap(or aResultWithAgenticScopeof aMap).- Throws:
IllegalArgumentException- if the decision model isnull, 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
-