Class SimpleToolSearchStrategy.Builder

java.lang.Object
dev.langchain4j.service.tool.search.simple.SimpleToolSearchStrategy.Builder
Enclosing class:
SimpleToolSearchStrategy

public static class SimpleToolSearchStrategy.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • maxResults

      public SimpleToolSearchStrategy.Builder maxResults(Integer maxResults)
      Sets the maximum number of tools to return after scoring and ranking.

      Default value is 5.

    • minScore

      public SimpleToolSearchStrategy.Builder minScore(Integer minScore)
      Sets the minimum score a tool must have to be included in the results.

      Tools with a score lower than this value are discarded.

      Default value is 1.

    • toolName

      public SimpleToolSearchStrategy.Builder toolName(String toolName)
      Sets the name of the tool that performs the tool search.

      Default value is "tool_search_tool".

    • toolDescription

      public SimpleToolSearchStrategy.Builder toolDescription(String toolDescription)
      Sets the description of the tool that performs the tool search.

      Default value is "Finds available tools whose name or description contains given search terms".

    • toolArgumentName

      public SimpleToolSearchStrategy.Builder toolArgumentName(String toolArgumentName)
      Sets the name of the tool argument that contains the list of search terms.

      Default value is "terms".

    • toolArgumentDescription

      public SimpleToolSearchStrategy.Builder toolArgumentDescription(String toolArgumentDescription)
      Sets the description of the tool argument that contains the list of search terms.

      Default value is "A list of search terms used to find relevant tools".

    • throwToolArgumentsExceptions

      public SimpleToolSearchStrategy.Builder throwToolArgumentsExceptions(Boolean throwToolArgumentsExceptions)
      Controls which exception type is thrown when tool arguments are missing, invalid, or cannot be parsed.

      Although all errors produced by this tool are argument-related, this strategy throws ToolExecutionException by default instead of ToolArgumentsException.

      The reason is historical: by default, AI Services fail fast when a ToolArgumentsException is thrown, whereas ToolExecutionException allows the error message to be returned to the LLM. For this tool, returning the error message to the LLM is usually the desired behavior.

      If this flag is set to true, ToolArgumentsException will be thrown instead.

      Parameters:
      throwToolArgumentsExceptions - whether to throw ToolArgumentsException
      Returns:
      this builder
    • toolResultMessageTextProvider

      public SimpleToolSearchStrategy.Builder toolResultMessageTextProvider(Function<List<String>, String> toolResultMessageTextProvider)
      Sets a function that produces a human-readable message describing the tool search result, based on the list of found tool names.

      By default, returns:

      • "No matching tools found" when no tools are found
      • "Tools found: <names>" otherwise
    • build

      public SimpleToolSearchStrategy build()