Interface MethodToolFactory
-
- All Implemented Interfaces:
public interface MethodToolFactoryFactory interface for creating tools from annotated methods. Extended by Tool.Companion to provide Tool.fromMethod, Tool.fromInstance, etc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMethodToolFactory.Companion
-
Method Summary
Modifier and Type Method Description ToolfromMethod(Object instance, KFunction<?> method, ObjectMapper objectMapper)Create a Tool from a Kotlin method annotated with LlmTool. ToolfromMethod(Object instance, Method method, ObjectMapper objectMapper)Create a Tool from a Java method annotated with LlmTool. List<Tool>fromInstance(Object instance, ObjectMapper objectMapper)Create Tools from all methods annotated with LlmTool on an instance. List<Tool>safelyFromInstance(Object instance, ObjectMapper objectMapper)Safely create Tools from an instance, returning empty list if no annotated methods found. -
-
Method Detail
-
fromMethod
Tool fromMethod(Object instance, KFunction<?> method, ObjectMapper objectMapper)
Create a Tool from a Kotlin method annotated with LlmTool.
- Parameters:
instance- The object instance containing the methodmethod- The Kotlin method to wrap as a toolobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
A Tool that invokes the method
-
fromMethod
Tool fromMethod(Object instance, Method method, ObjectMapper objectMapper)
Create a Tool from a Java method annotated with LlmTool.
- Parameters:
instance- The object instance containing the methodmethod- The Java method to wrap as a toolobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
A Tool that invokes the method
-
fromInstance
List<Tool> fromInstance(Object instance, ObjectMapper objectMapper)
Create Tools from all methods annotated with LlmTool on an instance.
If the instance's class is annotated with @UnfoldingTools or @MatryoshkaTools, returns a single UnfoldingTool containing all the inner tools. Otherwise, returns individual tools for each annotated method.
- Parameters:
instance- The object instance to scan for annotated methodsobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
List of Tools, one for each annotated method (or single UnfoldingTool if @UnfoldingTools/@MatryoshkaTools present)
-
safelyFromInstance
List<Tool> safelyFromInstance(Object instance, ObjectMapper objectMapper)
Safely create Tools from an instance, returning empty list if no annotated methods found. This is useful when you want to scan an object that may or may not have tool methods.
- Parameters:
instance- The object instance to scan for annotated methodsobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
List of Tools, or empty list if no annotated methods found
-
-
-
-