Class SimpleToolSearchStrategy
java.lang.Object
dev.langchain4j.service.tool.search.simple.SimpleToolSearchStrategy
- All Implemented Interfaces:
ToolSearchStrategy
A
ToolSearchStrategy that allows an LLM to search for available tools
using simple case-insensitive contains matching.
The LLM provides a list of search terms. Each term contributes to a tool's score:
+2if the tool name contains the term+1if the tool description contains the term
Scores are accumulated across all terms. Tools are ranked by score (descending)
and limited by maxResults.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionbuilder()extractTerms(String argumentsJson) getToolSearchTools(InvocationContext context) Returns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.protected intscore(ToolSpecification tool, List<String> terms) search(ToolSearchRequest request) Executes a tool search request generated by the LLM and matching it against searchable tools.
-
Constructor Details
-
SimpleToolSearchStrategy
public SimpleToolSearchStrategy() -
SimpleToolSearchStrategy
-
-
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:
context- 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
-
score
-
clean
-
extractTerms
-
builder
-