Class ToolSpecifications

java.lang.Object
dev.langchain4j.agent.tool.ToolSpecifications

public class ToolSpecifications extends Object
Utility methods for ToolSpecifications.
  • Method Details

    • toolSpecificationsFrom

      public static List<ToolSpecification> toolSpecificationsFrom(Class<?> classWithTools)
      Returns ToolSpecifications for all methods annotated with @Tool within the specified class.
      Parameters:
      classWithTools - the class.
      Returns:
      the ToolSpecifications.
    • toolSpecificationsFrom

      public static List<ToolSpecification> toolSpecificationsFrom(Object objectWithTools)
      Returns ToolSpecifications for all methods annotated with @Tool within the class of the specified object.
      Parameters:
      objectWithTools - the object.
      Returns:
      the ToolSpecifications.
    • validateSpecifications

      public static void validateSpecifications(List<ToolSpecification> toolSpecifications) throws IllegalArgumentException
      Validates all the ToolSpecifications. The validation checks for duplicate method names. Throws IllegalArgumentException if validation fails
      Parameters:
      toolSpecifications - list of ToolSpecification to be validated.
      Throws:
      IllegalArgumentException
    • toolSpecificationFrom

      public static ToolSpecification toolSpecificationFrom(Method method)
      Returns the ToolSpecification for the given method annotated with @Tool.
      Parameters:
      method - the method.
      Returns:
      the ToolSpecification.
    • toolNameFrom

      public static String toolNameFrom(Method method)
      Returns the name under which the given method is exposed to the LLM.

      A tool is named after the Java method that implements it:

      @Tool
      String currentTime() { ... } // the LLM sees a tool named "currentTime"
      
      unless the Tool.name() attribute is set, in which case that name is used instead:
      @Tool(name = "current_time")
      String currentTime() { ... } // the LLM sees a tool named "current_time"
      
      This is the name the LLM uses when it asks for the tool to be executed, so it is also the name carried by the resulting ToolExecutionRequest.
      Parameters:
      method - the method annotated with @Tool.
      Returns:
      the name of the tool.
      Since:
      1.21.0