Package com.tnsai.roles.metadata
Class RoleSpecExtractor
java.lang.Object
com.tnsai.roles.metadata.RoleSpecExtractor
Extracts role metadata from annotations.
Provides utilities to extract RoleIdentity, action metadata
(including action-bound mustNever / mustAlways safety
constraints), state, intentions, and LLM configuration from
annotation-based Role definitions.
Usage Example
if (RoleSpecExtractor.hasRoleIdentityAnnotation(MyRole.class)) {
RoleIdentity identity = RoleSpecExtractor.extractIdentity(MyRole.class).orElseThrow();
}
List<ResponsibilityInfo> actionResp =
RoleSpecExtractor.extractResponsibilitiesFromActions(MyRole.class);
- Author:
- TnsAI Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCached bundle of all extracted metadata for a role class.static final recordImmutable LLM configuration extracted from a role's@RoleSpec.llm()(@LLMSpec) for the role-export subsystem.static final recordImmutable responsibility information extracted from@ActionSpec.static final recordImmutable state information extracted from@Stateannotation.static final recordState with runtime value. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic StringderiveRoleName(Class<?> clazz) extractAll(Class<?> clazz) static Optional<RoleIdentity> extractIdentity(Class<?> clazz) extractIntentionsFromActions(Class<?> clazz) extractLLMSpec(Class<?> clazz) extractResponsibilitiesFromActions(Class<?> clazz) Extracts responsibilities from@ActionSpecannotated methods.static List<RoleSpecExtractor.StateInfo> extractStateFromFields(Class<?> clazz) static List<RoleSpecExtractor.StateValue> extractStateValues(Object role) static StringgetDescription(Class<?> clazz) static StringgetVersion(Class<?> clazz) static booleanhasLLMConfig(Class<?> clazz) static booleanhasRoleIdentityAnnotation(Class<?> clazz) static booleanhasStateFields(Class<?> clazz) static booleanusesAnnotations(Class<?> clazz)
-
Method Details
-
clearCache
public static void clearCache() -
hasRoleIdentityAnnotation
-
hasLLMConfig
-
usesAnnotations
-
extractIdentity
-
extractLLMSpec
-
deriveRoleName
-
getDescription
-
getVersion
-
extractStateFromFields
-
extractStateValues
-
extractIntentionsFromActions
-
extractResponsibilitiesFromActions
public static List<RoleSpecExtractor.ResponsibilityInfo> extractResponsibilitiesFromActions(Class<?> clazz) Extracts responsibilities from@ActionSpecannotated methods.Each entry carries the readable name, description, original method name, declared invariants, and the safety constraints (
mustNever/mustAlways) the action declares.- Parameters:
clazz- the class to scan- Returns:
- list of responsibility information per action
-
hasStateFields
-
extractAll
-