Class UnfoldingTool.Factory
-
- All Implemented Interfaces:
public class UnfoldingTool.FactoryFactory methods for creating UnfoldingTool instances. This is an open class so that subinterface companions can extend it.
-
-
Constructor Summary
Constructors Constructor Description UnfoldingTool.Factory()
-
Method Summary
Modifier and Type Method Description UnfoldingToolof(String name, String description, List<Tool> innerTools, Boolean removeOnInvoke, String childToolUsageNotes)Create an UnfoldingTool that exposes all inner tools when invoked. UnfoldingToolof(String name, String description, List<Tool> innerTools, Boolean removeOnInvoke)Create an UnfoldingTool that exposes all inner tools when invoked. UnfoldingToolof(String name, String description, List<Tool> innerTools)Create an UnfoldingTool that exposes all inner tools when invoked. UnfoldingToolselectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Boolean removeOnInvoke, String childToolUsageNotes, Function1<String, List<Tool>> selector)Create an UnfoldingTool with a custom tool selector. UnfoldingToolselectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Boolean removeOnInvoke, Function1<String, List<Tool>> selector)Create an UnfoldingTool with a custom tool selector. UnfoldingToolselectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Function1<String, List<Tool>> selector)Create an UnfoldingTool with a custom tool selector. UnfoldingToolbyCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter, Boolean removeOnInvoke, String childToolUsageNotes)Create an UnfoldingTool with category-based selection. UnfoldingToolbyCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter, Boolean removeOnInvoke)Create an UnfoldingTool with category-based selection. UnfoldingToolbyCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter)Create an UnfoldingTool with category-based selection. UnfoldingToolbyCategory(String name, String description, Map<String, List<Tool>> toolsByCategory)Create an UnfoldingTool with category-based selection. UnfoldingToolfromInstance(Object instance, ObjectMapper objectMapper)Create an UnfoldingTool from an instance annotated with @MatryoshkaTools. UnfoldingToolfromInstance(Object instance)Create an UnfoldingTool from an instance annotated with @MatryoshkaTools. UnfoldingToolsafelyFromInstance(Object instance, ObjectMapper objectMapper)Safely create an UnfoldingTool from an instance. UnfoldingToolsafelyFromInstance(Object instance)Safely create an UnfoldingTool from an instance. -
-
Method Detail
-
of
@JvmOverloads() UnfoldingTool of(String name, String description, List<Tool> innerTools, Boolean removeOnInvoke, String childToolUsageNotes)
Create an UnfoldingTool that exposes all inner tools when invoked.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- The tools to expose when invokedremoveOnInvoke- Whether to remove this tool after invocation (default true)childToolUsageNotes- Optional notes to guide LLM on using the child tools
-
of
@JvmOverloads() UnfoldingTool of(String name, String description, List<Tool> innerTools, Boolean removeOnInvoke)
Create an UnfoldingTool that exposes all inner tools when invoked.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- The tools to expose when invokedremoveOnInvoke- Whether to remove this tool after invocation (default true)
-
of
@JvmOverloads() UnfoldingTool of(String name, String description, List<Tool> innerTools)
Create an UnfoldingTool that exposes all inner tools when invoked.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- The tools to expose when invoked
-
selectable
@JvmOverloads() UnfoldingTool selectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Boolean removeOnInvoke, String childToolUsageNotes, Function1<String, List<Tool>> selector)
Create an UnfoldingTool with a custom tool selector.
The selector receives the JSON input string and returns the tools to expose. This enables category-based tool disclosure.
Example:
val fileTool = UnfoldingTool.selectable( name = "file_operations", description = "File operations. Pass 'category': 'read' or 'write'.", innerTools = allFileTools, inputSchema = Tool.InputSchema.of( Tool.Parameter.string("category", "The category of file operations", required = true) ), ) { input -> val json = ObjectMapper().readValue(input, Map::class.java) val category = json["category"] as? String when (category) { "read" -> listOf(readFileTool, listDirTool) "write" -> listOf(writeFileTool, deleteTool) else -> allFileTools } }- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- All possible inner toolsinputSchema- Schema describing the selection parametersremoveOnInvoke- Whether to remove this tool after invocationchildToolUsageNotes- Optional notes to guide LLM on using the child toolsselector- Function to select tools based on input
-
selectable
@JvmOverloads() UnfoldingTool selectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Boolean removeOnInvoke, Function1<String, List<Tool>> selector)
Create an UnfoldingTool with a custom tool selector.
The selector receives the JSON input string and returns the tools to expose. This enables category-based tool disclosure.
Example:
val fileTool = UnfoldingTool.selectable( name = "file_operations", description = "File operations. Pass 'category': 'read' or 'write'.", innerTools = allFileTools, inputSchema = Tool.InputSchema.of( Tool.Parameter.string("category", "The category of file operations", required = true) ), ) { input -> val json = ObjectMapper().readValue(input, Map::class.java) val category = json["category"] as? String when (category) { "read" -> listOf(readFileTool, listDirTool) "write" -> listOf(writeFileTool, deleteTool) else -> allFileTools } }- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- All possible inner toolsinputSchema- Schema describing the selection parametersremoveOnInvoke- Whether to remove this tool after invocationselector- Function to select tools based on input
-
selectable
@JvmOverloads() UnfoldingTool selectable(String name, String description, List<Tool> innerTools, Tool.InputSchema inputSchema, Function1<String, List<Tool>> selector)
Create an UnfoldingTool with a custom tool selector.
The selector receives the JSON input string and returns the tools to expose. This enables category-based tool disclosure.
Example:
val fileTool = UnfoldingTool.selectable( name = "file_operations", description = "File operations. Pass 'category': 'read' or 'write'.", innerTools = allFileTools, inputSchema = Tool.InputSchema.of( Tool.Parameter.string("category", "The category of file operations", required = true) ), ) { input -> val json = ObjectMapper().readValue(input, Map::class.java) val category = json["category"] as? String when (category) { "read" -> listOf(readFileTool, listDirTool) "write" -> listOf(writeFileTool, deleteTool) else -> allFileTools } }- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categoryinnerTools- All possible inner toolsinputSchema- Schema describing the selection parametersselector- Function to select tools based on input
-
byCategory
@JvmOverloads() UnfoldingTool byCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter, Boolean removeOnInvoke, String childToolUsageNotes)
Create an UnfoldingTool with category-based selection.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categorytoolsByCategory- Map of category names to their toolscategoryParameter- Name of the category parameter (default "category")removeOnInvoke- Whether to remove this tool after invocationchildToolUsageNotes- Optional notes to guide LLM on using the child tools
-
byCategory
@JvmOverloads() UnfoldingTool byCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter, Boolean removeOnInvoke)
Create an UnfoldingTool with category-based selection.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categorytoolsByCategory- Map of category names to their toolscategoryParameter- Name of the category parameter (default "category")removeOnInvoke- Whether to remove this tool after invocation
-
byCategory
@JvmOverloads() UnfoldingTool byCategory(String name, String description, Map<String, List<Tool>> toolsByCategory, String categoryParameter)
Create an UnfoldingTool with category-based selection.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categorytoolsByCategory- Map of category names to their toolscategoryParameter- Name of the category parameter (default "category")
-
byCategory
@JvmOverloads() UnfoldingTool byCategory(String name, String description, Map<String, List<Tool>> toolsByCategory)
Create an UnfoldingTool with category-based selection.
- Parameters:
name- Unique name for the tooldescription- Description explaining when to use this tool categorytoolsByCategory- Map of category names to their tools
-
fromInstance
@JvmOverloads() UnfoldingTool fromInstance(Object instance, ObjectMapper objectMapper)
Create an UnfoldingTool from an instance annotated with @MatryoshkaTools.
The instance's class must be annotated with
@MatryoshkaToolsand contain methods annotated with@LlmTool. If any@LlmToolmethods have acategoryspecified, a category-based UnfoldingTool is created; otherwise, all tools are exposed when the facade is invoked.Example - Simple facade:
@MatryoshkaTools( name = "database_operations", description = "Database operations. Invoke to see specific tools." ) public class DatabaseTools { @LlmTool(description = "Execute a SQL query") public QueryResult query(String sql) { ... } @LlmTool(description = "Insert a record") public InsertResult insert(String table, String data) { ... } } UnfoldingTool tool = UnfoldingTool.fromInstance(new DatabaseTools());Example - Category-based:
@MatryoshkaTools( name = "file_operations", description = "File operations. Pass category to select tools." ) public class FileTools { @LlmTool(description = "Read file", category = "read") public String readFile(String path) { ... } @LlmTool(description = "Write file", category = "write") public void writeFile(String path, String content) { ... } } UnfoldingTool tool = UnfoldingTool.fromInstance(new FileTools()); // Automatically creates category-based selection with "read" and "write" categories- Parameters:
instance- The object instance annotated with@MatryoshkaToolsobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
An UnfoldingTool wrapping the annotated methods
-
fromInstance
@JvmOverloads() UnfoldingTool fromInstance(Object instance)
Create an UnfoldingTool from an instance annotated with @MatryoshkaTools.
The instance's class must be annotated with
@MatryoshkaToolsand contain methods annotated with@LlmTool. If any@LlmToolmethods have acategoryspecified, a category-based UnfoldingTool is created; otherwise, all tools are exposed when the facade is invoked.Example - Simple facade:
@MatryoshkaTools( name = "database_operations", description = "Database operations. Invoke to see specific tools." ) public class DatabaseTools { @LlmTool(description = "Execute a SQL query") public QueryResult query(String sql) { ... } @LlmTool(description = "Insert a record") public InsertResult insert(String table, String data) { ... } } UnfoldingTool tool = UnfoldingTool.fromInstance(new DatabaseTools());Example - Category-based:
@MatryoshkaTools( name = "file_operations", description = "File operations. Pass category to select tools." ) public class FileTools { @LlmTool(description = "Read file", category = "read") public String readFile(String path) { ... } @LlmTool(description = "Write file", category = "write") public void writeFile(String path, String content) { ... } } UnfoldingTool tool = UnfoldingTool.fromInstance(new FileTools()); // Automatically creates category-based selection with "read" and "write" categories- Parameters:
instance- The object instance annotated with@MatryoshkaTools- Returns:
An UnfoldingTool wrapping the annotated methods
-
safelyFromInstance
@JvmOverloads() UnfoldingTool safelyFromInstance(Object instance, ObjectMapper objectMapper)
Safely create an UnfoldingTool from an instance. Returns null if the class is not annotated with
@MatryoshkaToolsor has no@LlmToolmethods.- Parameters:
instance- The object instance to checkobjectMapper- ObjectMapper for JSON parsing (optional)- Returns:
An UnfoldingTool if the instance is properly annotated, null otherwise
-
safelyFromInstance
@JvmOverloads() UnfoldingTool safelyFromInstance(Object instance)
Safely create an UnfoldingTool from an instance. Returns null if the class is not annotated with
@MatryoshkaToolsor has no@LlmToolmethods.- Parameters:
instance- The object instance to check- Returns:
An UnfoldingTool if the instance is properly annotated, null otherwise
-
-
-
-