Package com.tnsai.annotations
Annotation Interface BeforeActionSpec
Marks a method as a pre-processor for an action.
BeforeAction methods are invoked BEFORE the actual action execution, allowing you to:
- Transform parameters from LLM-friendly format to action format
- Inject sensitive data (API keys, tokens) that shouldn't be exposed to LLM
- Validate and enrich parameters before action execution
- Convert user-friendly inputs (city name) to technical inputs (lat/lon)
Execution Flow
LLM selects action with params
|
v
[BeforeAction method] -- transforms params
|
v
[Action executes] -- with transformed params
|
v
Result returned
Usage Example
// The action
@ActionSpec(
type = ActionType.WEB_SERVICE,
endpoint = "https://api.weather.com?lat={lat}&lon={lon}&appid={apiKey}",
description = "Get weather for coordinates"
)
public Object getWeather(String lat, String lon, ActionResult result) {
return formatWeather(result.asMap());
}
// The pre-processor - linked to getWeather action
@BeforeActionSpec("getWeather")
private void prepareWeather(ActionParams params) {
params.set("apiKey", System.getenv("WEATHER_API_KEY"));
}
BeforeAction Method Signature
BeforeAction methods must:
- Be in the same Role class as the action
- Accept a single
ActionParamsparameter - Return void (parameters are modified in-place)
- Can be private, protected, or public
- Author:
- TnsAI Team
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
value
String valueThe name of the main action method that this pre-processor is linked to. The action method must exist in the same Role class.- Returns:
- action method name
-