Class DecisionModelChatModelRouter.Builder

java.lang.Object
dev.langchain4j.model.chat.router.DecisionModelChatModelRouter.Builder
Enclosing class:
DecisionModelChatModelRouter

public static class DecisionModelChatModelRouter.Builder extends Object
Since:
1.21.0
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • decisionModel

      public DecisionModelChatModelRouter.Builder decisionModel(DecisionModel decisionModel)
      Sets the decision model that selects the route. Required.
    • question

      public DecisionModelChatModelRouter.Builder question(String 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

      public DecisionModelChatModelRouter.Builder minProbability(Double 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

      Sets what happens when the decision model fails.

      Default value is DecisionModelChatModelRouter.FallbackStrategy.DEFAULT_ROUTE.

    • maxMessages

      public DecisionModelChatModelRouter.Builder 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. 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 with messageFilter(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

      public DecisionModelChatModelRouter.Builder 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. 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, and message -> !(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