selectable
fun selectable(name: String, description: String, innerTools: List<Tool>, inputSchema: Tool.InputSchema, removeOnInvoke: Boolean = true, selector: (String) -> List<Tool>): MatryoshkaTool
Create a MatryoshkaTool 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 = MatryoshkaTool.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
selector
Function to select tools based on input