Record Class FunctionDefinition

java.lang.Object
java.lang.Record
dev.agenor.core.llm.FunctionDefinition
Record Components:
name - the name of the function
description - a description of what the function does
parameters - the JSON Schema defining the function's parameters

public record FunctionDefinition(String name, String description, Map<String,Object> parameters) extends Record
Defines a function that can be called by an LLM.

Function calling (also known as tool use) allows LLMs to request the execution of external functions to gather information or perform actions. This class describes the function's name, purpose, and parameters using JSON Schema.

Example usage:


 FunctionDefinition weatherFunction = FunctionDefinition.builder("get_weather")
     .description("Get the current weather for a location")
     .parameter("location", "string", "The city and state, e.g. San Francisco, CA", true)
     .parameter("unit", "string", "Temperature unit (celsius or fahrenheit)", false)
     .build();
 
Since:
0.3.0
  • Constructor Details

    • FunctionDefinition

      public FunctionDefinition(String name, String description, Map<String,Object> parameters)
      Compact constructor with validation and defensive copying.
  • Method Details

    • builder

      public static FunctionDefinition.Builder builder(String name)
      Create a new builder.
      Parameters:
      name - the function name
      Returns:
      a new builder
    • getParameterSchema

      public Map<String,Object> getParameterSchema()
      Get the parameter schema.
      Returns:
      the JSON Schema for parameters
    • getRequiredParameters

      public List<String> getRequiredParameters()
      Get the list of required parameters.
      Returns:
      list of required parameter names, or empty list if none
    • isParameterRequired

      public boolean isParameterRequired(String parameterName)
      Check if a parameter is required.
      Parameters:
      parameterName - the parameter name to check
      Returns:
      true if the parameter is required
    • getProperties

      public Map<String,Object> getProperties()
      Get the properties definition.
      Returns:
      map of parameter properties
    • toString

      public 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.
    • name

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

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

      public Map<String,Object> parameters()
      Returns the value of the parameters record component.
      Returns:
      the value of the parameters record component