selectable
open fun selectable(name: String, description: String, innerTools: List<Tool>, inputSchema: Tool.InputSchema, removeOnInvoke: Boolean = true, childToolUsageNotes: String? = null, selector: (String) -> List<Tool>): UnfoldingTool
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
}
}Content copied to clipboard
Parameters
name
Unique name for the tool
description
Description explaining when to use this tool category
inner Tools
All possible inner tools
input Schema
Schema describing the selection parameters
remove On Invoke
Whether to remove this tool after invocation
child Tool Usage Notes
Optional notes to guide LLM on using the child tools
selector
Function to select tools based on input