Class ActionParams

java.lang.Object
com.tnsai.actions.ActionParams

public class ActionParams extends Object
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 Details

    • ActionParams

      public ActionParams(Map<String,Object> llmParams, String actionName)
      Creates ActionParams with initial parameters from LLM.
      Parameters:
      llmParams - parameters provided by LLM
      actionName - name of the action being executed
  • Method Details

    • get

      public <T> T get(String name)
      Gets a parameter value.
      Parameters:
      name - parameter name
      Returns:
      parameter value or null if not present
    • get

      public <T> T get(String name, Class<T> type)
      Gets a parameter value with type conversion.
      Parameters:
      name - parameter name
      type - expected type class
      Returns:
      converted value or null if not present
    • getOrDefault

      public <T> T getOrDefault(String name, T defaultValue)
      Gets a parameter value with default.
      Parameters:
      name - parameter name
      defaultValue - value to return if parameter is not present
      Returns:
      parameter value or default
    • getString

      public String getString(String name)
      Gets a parameter value as String.
      Parameters:
      name - parameter name
      Returns:
      string value or null if not present
    • getInt

      public int getInt(String name)
      Gets a parameter value as int.
      Parameters:
      name - parameter name
      Returns:
      int value
      Throws:
      NumberFormatException - if value cannot be converted
    • getDouble

      public double getDouble(String name)
      Gets a parameter value as double.
      Parameters:
      name - parameter name
      Returns:
      double value
      Throws:
      NumberFormatException - if value cannot be converted
    • getBoolean

      public boolean getBoolean(String name)
      Gets a parameter value as boolean.
      Parameters:
      name - parameter name
      Returns:
      boolean value
    • set

      public ActionParams set(String name, Object value)
      Sets a parameter value.
      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      this instance for chaining
    • setAll

      public ActionParams setAll(Map<String,Object> values)
      Sets multiple parameters at once.
      Parameters:
      values - map of parameter names to values
      Returns:
      this instance for chaining
    • remove

      public Object remove(String name)
      Removes a parameter.
      Parameters:
      name - parameter name
      Returns:
      the removed value, or null if not present
    • has

      public boolean has(String name)
      Checks if a parameter exists.
      Parameters:
      name - parameter name
      Returns:
      true if parameter exists
    • names

      public Set<String> names()
      Gets all parameter names.
      Returns:
      set of parameter names
    • getActionName

      public String getActionName()
      Gets the action name this params belong to.
      Returns:
      action name
    • toMap

      public Map<String,Object> toMap()
      Returns all parameters as an unmodifiable map.
      Returns:
      parameter map
    • toString

      public String toString()
      Overrides:
      toString in class Object