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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PromptTemplateThe default template of the question asked for each tool:"Would this tool help to handle the request?\nTool: {{name}}\nDescription: {{description}}". -
Constructor Summary
ConstructorsModifierConstructorDescriptionDecisionModelToolSearchStrategy(DecisionModel decisionModel) protected -
Method Summary
Modifier and TypeMethodDescriptionbuilder()getToolSearchTools(InvocationContext invocationContext) Returns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.search(ToolSearchRequest request) Executes a tool search request generated by the LLM and matching it against searchable tools.
-
Field Details
-
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
-
DecisionModelToolSearchStrategy
-
DecisionModelToolSearchStrategy
-
-
Method Details
-
getToolSearchTools
Description copied from interface:ToolSearchStrategyReturns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.- Specified by:
getToolSearchToolsin interfaceToolSearchStrategy- Parameters:
invocationContext- the AI Service invocation context- Returns:
- list containing one or more tool search tools
-
search
Description copied from interface:ToolSearchStrategyExecutes a tool search request generated by the LLM and matching it against searchable tools.- Specified by:
searchin interfaceToolSearchStrategy- Parameters:
request- the tool search request- Returns:
- the search result containing matching tool names
-
builder
-