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
}
}

Parameters

name

Unique name for the tool

description

Description explaining when to use this tool category

innerTools

All possible inner tools

inputSchema

Schema describing the selection parameters

removeOnInvoke

Whether to remove this tool after invocation

selector

Function to select tools based on input