Package dev.agenor.core.llm
Record Class FunctionCall
java.lang.Object
java.lang.Record
dev.agenor.core.llm.FunctionCall
- Record Components:
id- the unique identifier for this function callname- the name of the function to be calledarguments- the arguments for the function as a JSON string
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 Summary
ConstructorsConstructorDescriptionFunctionCall(String id, String name, String arguments) Compact constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theargumentsrecord component.final booleanIndicates whether some other object is "equal to" this one.<T> TgetArgument(String key, Class<T> type) Get a specific argument value.getBooleanArgument(String key) Get a boolean argument.getDoubleArgument(String key) Get a double argument.getIntArgument(String key) Get an integer argument.getStringArgument(String key) Get a string argument.booleanCheck if this function call has arguments.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.name()Returns the value of thenamerecord component.static FunctionCallCreate a function call with no arguments.static FunctionCallCreate a function call with generated ID.Parse the arguments JSON string into a Map.toString()Returns a string representation of this record class.
-
Constructor Details
-
FunctionCall
Compact constructor with validation.
-
-
Method Details
-
of
Create a function call with generated ID.- Parameters:
name- the function namearguments- the arguments as JSON string- Returns:
- a new function call
-
of
Create a function call with no arguments.- Parameters:
name- the function name- Returns:
- a new function call with empty arguments
-
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
Get a specific argument value.- Type Parameters:
T- the expected type- Parameters:
key- the argument keytype- the expected class type- Returns:
- the argument value, or null if not found
-
getStringArgument
Get a string argument.- Parameters:
key- the argument key- Returns:
- the argument value as string, or null if not found
-
getIntArgument
Get an integer argument.- Parameters:
key- the argument key- Returns:
- the argument value as integer, or null if not found
-
getDoubleArgument
Get a double argument.- Parameters:
key- the argument key- Returns:
- the argument value as double, or null if not found
-
getBooleanArgument
Get a boolean argument.- Parameters:
key- the argument key- Returns:
- the argument value as boolean, or null if not found
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
arguments
Returns the value of theargumentsrecord component.- Returns:
- the value of the
argumentsrecord component
-