Package com.tnsai.actions
Class ActionParams
java.lang.Object
com.tnsai.actions.ActionParams
Holds parameters for action execution, supporting transformation between
LLM-provided parameters and actual action parameters.
ActionParams is passed to BeforeActionSpec methods
to allow parameter transformation before action execution.
Usage in BeforeAction
private void prepareWeatherParams(ActionParams params) {
// Read LLM-provided parameter
String city = params.get("city");
// Set action parameters
var coords = geocodeService.getCoordinates(city);
params.set("lat", coords.getLat());
params.set("lon", coords.getLon());
params.set("apiKey", System.getenv("WEATHER_API_KEY"));
// Optionally remove the LLM parameter if not needed by action
params.remove("city");
}
Parameter Flow
LLM: {city: "Istanbul"}
|
v
BeforeAction: reads "city", sets lat/lon/apiKey
|
v
Action receives: {lat: 41.0, lon: 28.9, apiKey: "xxx"}
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionActionParams(Map<String, Object> llmParams, String actionName) Creates ActionParams with initial parameters from LLM. -
Method Summary
Modifier and TypeMethodDescription<T> TGets a parameter value.<T> TGets a parameter value with type conversion.Gets the action name this params belong to.booleangetBoolean(String name) Gets a parameter value as boolean.doubleGets a parameter value as double.intGets a parameter value as int.<T> TgetOrDefault(String name, T defaultValue) Gets a parameter value with default.Gets a parameter value as String.booleanChecks if a parameter exists.names()Gets all parameter names.Removes a parameter.Sets a parameter value.Sets multiple parameters at once.toMap()Returns all parameters as an unmodifiable map.toString()
-
Constructor Details
-
ActionParams
Creates ActionParams with initial parameters from LLM.- Parameters:
llmParams- parameters provided by LLMactionName- name of the action being executed
-
-
Method Details
-
get
Gets a parameter value.- Parameters:
name- parameter name- Returns:
- parameter value or null if not present
-
get
Gets a parameter value with type conversion.- Parameters:
name- parameter nametype- expected type class- Returns:
- converted value or null if not present
-
getOrDefault
Gets a parameter value with default.- Parameters:
name- parameter namedefaultValue- value to return if parameter is not present- Returns:
- parameter value or default
-
getString
Gets a parameter value as String.- Parameters:
name- parameter name- Returns:
- string value or null if not present
-
getInt
Gets a parameter value as int.- Parameters:
name- parameter name- Returns:
- int value
- Throws:
NumberFormatException- if value cannot be converted
-
getDouble
Gets a parameter value as double.- Parameters:
name- parameter name- Returns:
- double value
- Throws:
NumberFormatException- if value cannot be converted
-
getBoolean
Gets a parameter value as boolean.- Parameters:
name- parameter name- Returns:
- boolean value
-
set
Sets a parameter value.- Parameters:
name- parameter namevalue- parameter value- Returns:
- this instance for chaining
-
setAll
Sets multiple parameters at once.- Parameters:
values- map of parameter names to values- Returns:
- this instance for chaining
-
remove
Removes a parameter.- Parameters:
name- parameter name- Returns:
- the removed value, or null if not present
-
has
Checks if a parameter exists.- Parameters:
name- parameter name- Returns:
- true if parameter exists
-
names
Gets all parameter names.- Returns:
- set of parameter names
-
getActionName
Gets the action name this params belong to.- Returns:
- action name
-
toMap
Returns all parameters as an unmodifiable map.- Returns:
- parameter map
-
toString
-