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) }
    • 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
      Tool.Definition getDefinition() Tool definition for LLM
      Tool.Metadata getMetadata()
      O typedCall(I input) Execute the tool with strongly typed input.
      Tool.Result call(String input) Executes the tool by deserializing input JSON, calling typedCall, and serializing the result.
      • 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

      • 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 consumption
        description - Tool description for LLM consumption
        inputType - Class of the input type for JSON deserialization
        outputType - Class of the output type (used for documentation)
        metadata - Optional tool metadata
        objectMapper - ObjectMapper for JSON serialization/deserialization
        function - Function that processes typed input and returns typed output
    • Method Detail

      • 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