Class DecisionModelChatModelRouter.Builder
java.lang.Object
dev.langchain4j.model.chat.router.DecisionModelChatModelRouter.Builder
- Enclosing class:
DecisionModelChatModelRouter
- Since:
- 1.21.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()decisionModel(DecisionModel decisionModel) Sets the decision model that selects the route.fallbackStrategy(DecisionModelChatModelRouter.FallbackStrategy fallbackStrategy) Sets what happens when the decision model fails.maxMessageLength(Integer maxMessageLength) Sets the maximum length, in characters, of the text of each message the decision model receives, other than system messages, and of the arguments of each tool call.maxMessages(Integer maxMessages) Sets the maximum number of messages of the conversation that the decision model receives: the last messages of the request, plus the last user message if it is older.messageFilter(Predicate<? super ChatMessage> messageFilter) Sets which messages of the conversation the decision model receives; it also applies to the last user message.minProbability(Double minProbability) Sets the minimum probability of the chosen route.Sets the question asked to choose between the routes, whose descriptions are the options.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
decisionModel
Sets the decision model that selects the route. Required. -
question
Sets the question asked to choose between the routes, whose descriptions are the options.It is a plain question rather than a template: all routes are the options of a single choice question, so there is nothing to insert into the question.
Default value is "Which model should handle this request?".
-
minProbability
Sets the minimum probability of the chosen route. Below it, the router does not select a route, so the default route of the routing chat model is used, for example a larger model when the decision model is not sure. Requires a decision model that reports probabilities. Optional: by default, the chosen route is always used. -
fallbackStrategy
public DecisionModelChatModelRouter.Builder fallbackStrategy(DecisionModelChatModelRouter.FallbackStrategy fallbackStrategy) Sets what happens when the decision model fails.Default value is
DecisionModelChatModelRouter.FallbackStrategy.DEFAULT_ROUTE. -
maxMessages
Sets the maximum number of messages of the conversation that the decision model receives: the last messages of the request, plus the last user message if it is older. An AI message with tool calls and each tool result count as one message each. Tool results whose AI message does not fit are left out. With parallel tool calls, set it higher than the number of tool calls in one round. With 1, system messages are still sent; leave them out withmessageFilter(Predicate). System messages are sent in addition and do not count. Previous messages help with follow-ups whose meaning depends on them; too many can make an older topic outweigh the last message.Default value is 10.
-
maxMessageLength
Sets the maximum length, in characters, of the text of each message the decision model receives, other than system messages, and of the arguments of each tool call. A longer text is shortened in the middle: its beginning and its end are kept, with a note of about 90 characters saying how many characters were left out. Long tool results and user messages with retrieved content are the usual cases. As a rough guide, 4 characters make one token in English text.Default value is 2000.
- Since:
- 1.23.0
-
messageFilter
public DecisionModelChatModelRouter.Builder messageFilter(Predicate<? super ChatMessage> messageFilter) Sets which messages of the conversation the decision model receives; it also applies to the last user message. For example,message -> !(message instanceof SystemMessage)leaves out the system message, andmessage -> !(message instanceof ToolExecutionResultMessage)leaves out tool results, which can be large.By default, all messages are sent: system messages, user messages, AI messages with their tool calls, and tool results.
- Since:
- 1.23.0
-
build
-