Annotation Interface RoleSpec
This is the primary annotation for defining agent roles with
LLM configuration and metadata. Safety constraints
(mustNever / mustAlways) are declared on
@ActionSpec methods of the role class — every constraint
lives on the action it applies to.
A class without its own specification inherits the nearest superclass specification. A subclass declaration replaces the complete specification; individual fields are not merged. Interface specifications are not inherited.
Automatic Extraction
The following are extracted automatically from code:
- State: From
@Stateannotated fields - Actions: From
@ActionSpecannotated methods
Usage
@RoleSpec(
name = "LifeCell",
description = "Conway's Game of Life cellular automaton"
)
public class LifeCellRole extends Role {
@State(description = "Current cell state")
private CellState cellState = CellState.DEAD;
@ActionSpec(
type = ActionType.LOCAL,
description = "Update cell state",
mustNever = {"transition to invalid state"}
)
public void updateState() { ... }
}
- Author:
- TnsAI Team
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionCommunication configuration for this role.The role's own configuration file, which can override and add to this role'sllmandknowledge.Role description.String[]Domains this role operates in.Goal[]Goals this role wants to achieve.Knowledge this role's actions can use.Presence policies for the sourcesknowledge()and this role's configuration file declare.LLM configuration for this role.Role name.intRole priority (higher = more important).LLM capabilities this role actually exercises at runtime — surfaced to the build-time validation pipeline (AGENT-V004, issue #238) so a missing capability on the configured LLM fails fast atAgentBuilder.build()rather than at the first streaming / vision / structured-output call.booleanWhether this role can be assigned to multiple agents simultaneously.Role version (semantic versioning).
-
Element Details
-
name
String nameRole name.If empty, class name is used.
- Returns:
- role name
- Default:
""
-
description
String descriptionRole description.Used in system prompts and documentation.
- Returns:
- description
- Default:
""
-
version
String versionRole version (semantic versioning).- Returns:
- version string
- Default:
"1.0.0"
-
priority
int priorityRole priority (higher = more important).Used when multiple roles could handle a task.
- Default:
5
-
domains
String[] domainsDomains this role operates in.- Returns:
- domain names
- Default:
{}
-
llm
LLMSpec llmLLM configuration for this role.@RoleSpec( name = "ResearchAgent", llm = @LLMSpec( provider = Provider.OLLAMA, model = "llama3", temperature = 0.7f ) )- Returns:
- LLM configuration
- Default:
@com.tnsai.annotations.LLMSpec
-
communication
Communication communicationCommunication configuration for this role.- Returns:
- Communication configuration
- Default:
@com.tnsai.annotations.Communication
-
requires
LLMCapability[] requiresLLM capabilities this role actually exercises at runtime — surfaced to the build-time validation pipeline (AGENT-V004, issue #238) so a missing capability on the configured LLM fails fast atAgentBuilder.build()rather than at the first streaming / vision / structured-output call.Each value in the array maps 1:1 to a flag on
LLMCapabilities; the validator emits oneAGENT-V004WARNING per capability the LLM reports as unsupported.Default empty array — undeclared roles are silent (validator has no signal to act on). Function calling is NOT a value of
LLMCapabilityon purpose: that case is already covered byAGENT-V003via tool-presence detection, no annotation required.@RoleSpec( name = "VisionResearcher", requires = {LLMCapability.VISION, LLMCapability.STREAMING} ) public class VisionResearcherRole extends Role { ... }- Returns:
- required LLM capabilities for this role
- Since:
- 0.8.5 (issue #238)
- Default:
{}
-
goals
Goal[] goalsGoals this role wants to achieve.Goals define desired states that the planner will work towards. Each goal has a condition that determines when it's satisfied.
@RoleSpec( name = "LifeCell", goals = { @Goal(name = "survive", condition = "state == ALIVE", priority = Priority.CRITICAL), @Goal(name = "reproduce", condition = "neighborCount == 3", priority = Priority.HIGH) } )Actions can be linked to goals via
:invalid reference
Action#fulfills()@ActionSpec( precondition = "state == DEAD && neighborCount == 3", postcondition = "state = ALIVE", fulfills = {"survive", "reproduce"} ) public void reproduce() { ... }- Returns:
- goals for planning
- See Also:
- Default:
{}
-
knowledge
Knowledge[] knowledgeKnowledge this role's actions can use.Each entry declares a source once; an action sees a source only when its
ActionSpec.knowledge()names it. Two entries with the sameKnowledge.name()fail at startup.- Returns:
- knowledge declarations (empty by default)
- Since:
- 0.18.0
- See Also:
- Default:
{}
-
knowledgePolicy
KnowledgePolicy[] knowledgePolicyPresence policies for the sourcesknowledge()and this role's configuration file declare. A source without a policy must load.- Returns:
- knowledge policies (empty by default)
- Since:
- 0.18.1
- See Also:
- Default:
{}
-
config
Config configThe role's own configuration file, which can override and add to this role'sllmandknowledge. It wins over therolessection of an agent's file. No path means no file.- Returns:
- the configuration file
- Since:
- 0.18.0
- See Also:
- Default:
@com.tnsai.annotations.Config
-