Class DecisionModelToolSearchStrategy

java.lang.Object
dev.langchain4j.service.tool.search.decision.DecisionModelToolSearchStrategy
All Implemented Interfaces:
ToolSearchStrategy

@Experimental public class DecisionModelToolSearchStrategy extends Object implements ToolSearchStrategy
A ToolSearchStrategy that uses a DecisionModel to find the tools matching the search query of the LLM: for each searchable tool, the decision model answers whether the tool would help with the query (all tools in a single call), and the most relevant tools are returned.
Assistant assistant = AiServices.builder(Assistant.class)
        .chatModel(chatModel)
        .toolProvider(mcpToolProvider)
        .toolSearchStrategy(new DecisionModelToolSearchStrategy(decisionModel))
        .build();
Unlike an embedding-based search, the decision model reads the descriptions of the tools and the query together, so it can find tools that match by meaning rather than by wording. If the decision model fails, the exception is propagated to the tool-calling loop like the error of any tool.
Since:
1.21.0
See Also:
  • Field Details

    • DEFAULT_QUESTION_TEMPLATE

      public static final PromptTemplate DEFAULT_QUESTION_TEMPLATE
      The default template of the question asked for each tool: "Would this tool help to handle the request?\nTool: {{name}}\nDescription: {{description}}".
  • Constructor Details

  • Method Details