Package com.embabel.agent.core.hitl
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) } }
-
-
Field Summary
Fields Modifier and Type Field Description private final Tool.Definitiondefinitionprivate final Tool.Metadatametadata
-
Constructor Summary
Constructors Constructor Description AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType, Tool.Metadata metadata, ObjectMapper objectMapper)AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType, Tool.Metadata metadata)AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType)
-
Method Summary
Modifier and Type Method Description abstract Awaitable<P, ?>createAwaitable(I input)Check if this tool invocation requires human input. abstract Oexecute(I input)Execute the tool logic after any awaitable has been resolved. final OtypedCall(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 consumptiondescription- Tool description for LLM consumptioninputType- Class of the input type for JSON deserializationoutputType- Class of the output typemetadata- Optional tool metadataobjectMapper- 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 consumptiondescription- Tool description for LLM consumptioninputType- Class of the input type for JSON deserializationoutputType- Class of the output typemetadata- Optional tool metadata
-
AwaitableTypedTool
AwaitableTypedTool(String name, String description, Class<I> inputType, Class<O> outputType)
- Parameters:
name- Tool name for LLM consumptiondescription- Tool description for LLM consumptioninputType- Class of the input type for JSON deserializationoutputType- 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
-
-
-
-