Awaitable Typed Tool
Abstract typed tool that supports Human-in-the-Loop (HITL) interactions.
Before executing the main tool logic, this tool checks if human input is required via createAwaitable. If an Awaitable is returned, the tool throws AwaitableResponseException to pause execution and wait for user response.
Example usage:
data class DeleteRequest(val path: String, val force: Boolean = false)
data class DeleteResult(val deleted: Boolean, val path: String)
class ConfirmingDeleteTool : AwaitableTypedTool<DeleteRequest, DeleteResult, DeleteRequest>(
name = "delete_file",
description = "Delete a file with confirmation",
inputType = DeleteRequest::class.java,
outputType = DeleteResult::class.java,
) {
override fun createAwaitable(input: DeleteRequest): Awaitable<DeleteRequest, *>? {
// Only confirm for non-force deletes
return if (!input.force) {
ConfirmationRequest(input, "Delete ${input.path}?")
} else null
}
override fun execute(input: DeleteRequest): DeleteResult {
val success = Files.deleteIfExists(Path.of(input.path))
return DeleteResult(deleted = success, path = input.path)
}
}Parameters
Input type - will be deserialized from JSON
Output type - will be serialized to JSON
Payload type for the awaitable (often same as I)
Tool name for LLM consumption
Tool description for LLM consumption
Class of the input type for JSON deserialization
Class of the output type
Optional tool metadata
ObjectMapper for JSON serialization/deserialization
Functions
Execute the tool with JSON input and out-of-band context.
Executes the tool by deserializing input JSON, calling typedCall, and serializing the result.
Check if this tool invocation requires human input.
Extension function to convert an Embabel Tool to a Spring AI ToolCallback.
Wrap this tool to conditionally await before execution.
Wrap this tool to always require confirmation before execution.
Create a new tool with additional definition metadata entries merged in. Existing keys are overwritten by the new values.
Create a new tool with a single definition metadata entry added.
Create a new tool with a different description. Useful for providing context-specific descriptions while keeping the same functionality.
Extension function to wrap a Tool with event publication.