Class AwaitableTypedTool

  • All Implemented Interfaces:
    com.embabel.agent.api.tool.Tool , com.embabel.agent.api.tool.ToolInfo

    
    public abstract class AwaitableTypedTool<I extends Object, O extends Object, P extends Object>
    extends TypedTool<I, O>
                        

    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)
        }
    }
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Awaitable<P, ?> createAwaitable(I input) Check if this tool invocation requires human input.
      abstract O execute(I input) Execute the tool logic after any awaitable has been resolved.
      final O typedCall(I input) Execute the tool with strongly typed input.
      • Methods inherited from class com.embabel.agent.api.tool.TypedTool

        call, getDefinition, getMetadata
      • Methods inherited from class com.embabel.agent.api.tool.Tool

        withDescription, withName, withNote
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AwaitableTypedTool

        AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType, Tool.Metadata metadata, ObjectMapper objectMapper)
        Parameters:
        name - Tool name for LLM consumption
        description - Tool description for LLM consumption
        inputType - Class of the input type for JSON deserialization
        outputType - Class of the output type
        metadata - Optional tool metadata
        objectMapper - ObjectMapper for JSON serialization/deserialization
      • AwaitableTypedTool

        AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType, Tool.Metadata metadata)
        Parameters:
        name - Tool name for LLM consumption
        description - Tool description for LLM consumption
        inputType - Class of the input type for JSON deserialization
        outputType - Class of the output type
        metadata - Optional tool metadata
      • AwaitableTypedTool

        AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType)
        Parameters:
        name - Tool name for LLM consumption
        description - Tool description for LLM consumption
        inputType - Class of the input type for JSON deserialization
        outputType - Class of the output type
    • Method Detail

      • createAwaitable

         abstract Awaitable<P, ?> createAwaitable(I input)

        Check if this tool invocation requires human input.

        Parameters:
        input - The parsed input
        Returns:

        An Awaitable if human input is required, null to proceed normally

      • execute

         abstract O execute(I input)

        Execute the tool logic after any awaitable has been resolved.

        Parameters:
        input - The parsed input
        Returns:

        The tool output

      • typedCall

         final O typedCall(I input)

        Execute the tool with strongly typed input. Calls the function provided at construction time. Can be overridden in subclasses for custom behavior.

        Parameters:
        input - Deserialized input object
        Returns:

        Output object (will be serialized to JSON)