Package com.embabel.agent.api.tool
Class TypedTool
-
- All Implemented Interfaces:
-
com.embabel.agent.api.tool.Tool,com.embabel.agent.api.tool.ToolInfo
public class TypedTool<I extends Object, O extends Object> implements Tool
Tool with strongly typed input and output. Handles JSON marshaling automatically, allowing you to work with domain objects directly.
Example usage:
data class AddRequest(val a: Int, val b: Int) data class AddResult(val sum: Int) val addTool = TypedTool( name = "add", description = "Add two numbers", inputType = AddRequest::class.java, outputType = AddResult::class.java, ) { input -> AddResult(input.a + input.b) }
-
-
Field Summary
Fields Modifier and Type Field Description private final Tool.Definitiondefinitionprivate final Tool.Metadatametadata
-
Method Summary
Modifier and Type Method Description Tool.DefinitiongetDefinition()Tool definition for LLM Tool.MetadatagetMetadata()OtypedCall(I input)Execute the tool with strongly typed input. Tool.Resultcall(String input)Executes the tool by deserializing input JSON, calling typedCall, and serializing the result. -
-
Constructor Detail
-
TypedTool
TypedTool(String name, String description, Class<I> inputType, Class<O> outputType, Tool.Metadata metadata, ObjectMapper objectMapper, Function<I, O> function)
- 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 (used for documentation)metadata- Optional tool metadataobjectMapper- ObjectMapper for JSON serialization/deserializationfunction- Function that processes typed input and returns typed output
-
-
Method Detail
-
getDefinition
Tool.Definition getDefinition()
Tool definition for LLM
-
getMetadata
Tool.Metadata getMetadata()
-
typedCall
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)
-
call
Tool.Result call(String input)
Executes the tool by deserializing input JSON, calling typedCall, and serializing the result.
- Parameters:
input- JSON string matching inputSchema
-
-
-
-