Class ToolSpecifications
java.lang.Object
dev.langchain4j.agent.tool.ToolSpecifications
Utility methods for
ToolSpecifications.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringtoolNameFrom(Method method) Returns the name under which the given method is exposed to the LLM.static ToolSpecificationtoolSpecificationFrom(Method method) Returns theToolSpecificationfor the given method annotated with @Tool.static List<ToolSpecification> toolSpecificationsFrom(Class<?> classWithTools) ReturnsToolSpecifications for all methods annotated with @Toolwithin the specified class.static List<ToolSpecification> toolSpecificationsFrom(Object objectWithTools) ReturnsToolSpecifications for all methods annotated with @Toolwithin the class of the specified object.static voidvalidateSpecifications(List<ToolSpecification> toolSpecifications) Validates all theToolSpecifications.
-
Method Details
-
toolSpecificationsFrom
ReturnsToolSpecifications for all methods annotated with @Toolwithin the specified class.- Parameters:
classWithTools- the class.- Returns:
- the
ToolSpecifications.
-
toolSpecificationsFrom
ReturnsToolSpecifications for all methods annotated with @Toolwithin 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 theToolSpecifications. The validation checks for duplicate method names. ThrowsIllegalArgumentExceptionif validation fails- Parameters:
toolSpecifications- list of ToolSpecification to be validated.- Throws:
IllegalArgumentException
-
toolSpecificationFrom
Returns theToolSpecificationfor the given method annotated with @Tool.- Parameters:
method- the method.- Returns:
- the
ToolSpecification.
-
toolNameFrom
Returns the name under which the given method is exposed to the LLM.A tool is named after the Java method that implements it:
unless the@Tool String currentTime() { ... } // the LLM sees a tool named "currentTime"Tool.name()attribute is set, in which case that name is used instead:
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@Tool(name = "current_time") String currentTime() { ... } // the LLM sees a tool named "current_time"ToolExecutionRequest.- Parameters:
method- the method annotated with @Tool.- Returns:
- the name of the tool.
- Since:
- 1.21.0
-