Interface ToolSearchStrategy
- All Known Implementing Classes:
SimpleToolSearchStrategy, VectorToolSearchStrategy
Strategy for discovering tools dynamically by an LLM during an AI Service invocation.
A ToolSearchStrategy allows reducing token usage by avoiding sending all available
tools to the LLM upfront. Instead, the LLM is initially exposed only to one or more
tool search tools, which it can call to discover relevant tools on demand.
Once the LLM performs a tool search, the matching tools are included in subsequent requests, typically accumulating until the corresponding search result message is evicted from the chat memory.
LangChain4j provides out-of-the-box implementations such as
SimpleToolSearchStrategy
and VectorToolSearchStrategy,
but custom strategies can be implemented to support alternative discovery mechanisms.
- Since:
- 1.12.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetToolSearchTools(InvocationContext invocationContext) Returns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.search(ToolSearchRequest toolSearchRequest) Executes a tool search request generated by the LLM and matching it against searchable tools.
-
Method Details
-
getToolSearchTools
Returns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.- Parameters:
invocationContext- the AI Service invocation context- Returns:
- list containing one or more tool search tools
-
search
Executes a tool search request generated by the LLM and matching it against searchable tools.- Parameters:
toolSearchRequest- the tool search request- Returns:
- the search result containing matching tool names
-