Record Class ToolExample

java.lang.Object
java.lang.Record
com.tnsai.tools.ToolExample
Record Components:
input - the example input/query
description - human-readable description of what this example demonstrates
expectedOutput - optional expected output (for documentation)
category - optional category to group examples

public record ToolExample(String input, String description, String expectedOutput, String category) extends Record
Represents a usage example for a tool.

Tool examples help LLMs understand how to use tools effectively by providing concrete input/output pairs with descriptions.

Usage


 // Simple example
 ToolExample example = ToolExample.of(
     "quantum physics",
     "Search for quantum physics articles"
 );

 // Example with expected output
 ToolExample example = ToolExample.withOutput(
     "2 + 2",
     "Simple addition",
     "4"
 );

 // Detailed example
 ToolExample example = ToolExample.builder()
     .input("weather in Tokyo")
     .description("Get current weather for Tokyo")
     .expectedOutput("Temperature: 15°C, Sunny")
     .category("weather")
     .build();
 
  • Constructor Details

    • ToolExample

      public ToolExample(String input, String description, String expectedOutput, String category)
      Creates a tool example with validation.
  • Method Details

    • of

      public static ToolExample of(String input, String description)
      Creates a simple tool example.
      Parameters:
      input - the example input
      description - what this example demonstrates
      Returns:
      new tool example
    • withOutput

      public static ToolExample withOutput(String input, String description, String expectedOutput)
      Creates a tool example with expected output.
      Parameters:
      input - the example input
      description - what this example demonstrates
      expectedOutput - the expected output
      Returns:
      new tool example
    • categorized

      public static ToolExample categorized(String input, String description, String category)
      Creates a categorized tool example.
      Parameters:
      input - the example input
      description - what this example demonstrates
      category - the example category
      Returns:
      new tool example
    • builder

      public static ToolExample.Builder builder()
      Creates a tool example builder.
      Returns:
      new builder
    • format

      public String format()
      Formats this example for LLM consumption.
      Returns:
      formatted example string
    • formatCompact

      public String formatCompact()
      Formats this example in a compact single-line format.
      Returns:
      compact format
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • input

      public String input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • expectedOutput

      public String expectedOutput()
      Returns the value of the expectedOutput record component.
      Returns:
      the value of the expectedOutput record component
    • category

      public String category()
      Returns the value of the category record component.
      Returns:
      the value of the category record component