Record Class FunctionCall

java.lang.Object
java.lang.Record
dev.agenor.core.llm.FunctionCall
Record Components:
id - the unique identifier for this function call
name - the name of the function to be called
arguments - the arguments for the function as a JSON string

public record FunctionCall(String id, String name, String arguments) extends Record
Represents a function call requested by an LLM.

When an LLM determines it needs to call a function to gather information or perform an action, it returns a FunctionCall object containing the function name and arguments.

The arguments are typically provided as a JSON string that can be parsed into the appropriate parameter types.

Example usage:


 // LLM response contains a function call
 if (response.hasFunctionCalls()) {
     FunctionCall call = response.functionCalls().get(0);
     String functionName = call.name();
     Map<String, Object> args = parseArguments(call.arguments());

     // Execute the function
     String result = executeFunction(functionName, args);

     // Send result back to LLM
     request = request.withFunctionResult(functionName, result);
 }
 
Since:
0.3.0
  • Constructor Details

    • FunctionCall

      public FunctionCall(String id, String name, String arguments)
      Compact constructor with validation.
  • Method Details

    • of

      public static FunctionCall of(String name, String arguments)
      Create a function call with generated ID.
      Parameters:
      name - the function name
      arguments - the arguments as JSON string
      Returns:
      a new function call
    • of

      public static FunctionCall of(String name)
      Create a function call with no arguments.
      Parameters:
      name - the function name
      Returns:
      a new function call with empty arguments
    • parseArguments

      public Map<String,Object> parseArguments()
      Parse the arguments JSON string into a Map.

      This is a convenience method for parsing the arguments. In practice, you'll likely want to use a proper JSON library like Jackson or Gson.

      Returns:
      the arguments as a map, or empty map if parsing fails
    • hasArguments

      public boolean hasArguments()
      Check if this function call has arguments.
      Returns:
      true if arguments are present and non-empty
    • getArgument

      public <T> T getArgument(String key, Class<T> type)
      Get a specific argument value.
      Type Parameters:
      T - the expected type
      Parameters:
      key - the argument key
      type - the expected class type
      Returns:
      the argument value, or null if not found
    • getStringArgument

      public String getStringArgument(String key)
      Get a string argument.
      Parameters:
      key - the argument key
      Returns:
      the argument value as string, or null if not found
    • getIntArgument

      public Integer getIntArgument(String key)
      Get an integer argument.
      Parameters:
      key - the argument key
      Returns:
      the argument value as integer, or null if not found
    • getDoubleArgument

      public Double getDoubleArgument(String key)
      Get a double argument.
      Parameters:
      key - the argument key
      Returns:
      the argument value as double, or null if not found
    • getBooleanArgument

      public Boolean getBooleanArgument(String key)
      Get a boolean argument.
      Parameters:
      key - the argument key
      Returns:
      the argument value as boolean, or null if not found
    • 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.
    • id

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

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

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