Class AgentSpecExtractor
AgentSpec annotation.
Converts annotation values to runtime models, providing defaults when annotation is not present.
Usage
AgentSpecExtractor extractor = new AgentSpecExtractor(MyAgent.class);
String description = extractor.getDescription();
Communication communication = extractor.getCommunication();
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAgentSpecExtractor(Class<?> agentClass) Creates extractor for an agent class. -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<GroupMemberSpec> extractGroupSpec(Class<?> agentClass) Static method to extract group configuration from an agent class.static List<KnowledgeSourceConfig> extractKnowledgeSources(Class<?> agentClass) Static accessor forgetKnowledgeSources().static intextractMaxContextTokens(Class<?> agentClass) Static accessor for the agent-level context-token budget from@AgentSpec.maxContextTokens(TNS-609).static Optional<MemorySpec> extractMemorySpec(Class<?> agentClass) Static method to extract memory configuration from an agent class.static Optional<RetrievalConfig> extractRetrieval(Class<?> agentClass) Static accessor forgetRetrieval().static ToolCallFilterextractToolCallFilter(Class<?> agentClass) Static accessor for the declarativeToolCallFilterfrom@AgentSpec.toolCallFilter(TNS-611).generateDID(String agentId) Generates the full DID string for the agent, delegating the default substitution toDIDConfig.toDid(String)so the annotation and builder paths produce identical DIDs.Extracts communication configuration as runtime model.Returns the agent description.Extracts group membership configuration from @AgentSpec.groups.intReturns idle timeout in milliseconds.Knowledge declared on@AgentSpec.knowledge(), each entry with its resolveduse, budget and search settings.getKnowledgeSource(String name) Resolves a named knowledge source declared on the Agent class and normalizes it to the canonical runtime model.Action-level sources declared on@AgentSpec.knowledge().intReturns the agent-level context-token budget from@AgentSpec.maxContextTokens(TNS-609).Extracts memory configuration from @AgentSpec.memory.Search settings of the@AgentSpec.knowledge()entries searched together, merged field by field.getRoles()Instantiates the role classes declared in@AgentSpec.roles(TNS-536) — the annotation counterpart ofAgentBuilder.role(...).Instantiates the declarativeToolCallFilterfrom@AgentSpec.toolCallFilter(TNS-611).Returns the agent version.booleanChecks if the agent has group membership configured.booleanChecks if the agent has memory configuration.booleanhasSpec()Checks if the class has @AgentSpec annotation.booleanReturns whether agent should auto-start.
-
Constructor Details
-
AgentSpecExtractor
Creates extractor for an agent class.- Parameters:
agentClass- the agent class to extract metadata from
-
-
Method Details
-
hasSpec
public boolean hasSpec()Checks if the class has @AgentSpec annotation.- Returns:
- true if annotation is present
-
getDescription
Returns the agent description.- Returns:
- description or empty string if not set
-
getVersion
Returns the agent version.- Returns:
- version string (default: "1.0.0")
-
isAutoStart
public boolean isAutoStart()Returns whether agent should auto-start.- Returns:
- true for auto-start (default: true)
-
getIdleTimeoutMs
public int getIdleTimeoutMs()Returns idle timeout in milliseconds.- Returns:
- timeout (0 = never suspend)
-
getMaxContextTokens
public int getMaxContextTokens()Returns the agent-level context-token budget from@AgentSpec.maxContextTokens(TNS-609).0when no@AgentSpecis present or the field is unset.- Returns:
- max context tokens (0 = no agent-level cap)
-
getToolCallFilter
Instantiates the declarativeToolCallFilterfrom@AgentSpec.toolCallFilter(TNS-611). The defaultAllowAllToolFilteris treated as the "not set" sentinel and returnsnullso the agent runs with no filter wired (preserving the pre-TNS-611 behaviour and keeping AGENT-V006 honest).- Returns:
- an instantiated filter, or
nullwhen no declarative filter is set - Throws:
IllegalStateException- AGENT-V009 if the declared filter class lacks a public no-arg constructor or otherwise fails to instantiate- Since:
- 0.12.0 (TNS-611)
-
getRoles
Instantiates the role classes declared in@AgentSpec.roles(TNS-536) — the annotation counterpart ofAgentBuilder.role(...). Each class is created via its public no-arg constructor.- Returns:
- the instantiated roles (empty if none declared)
- Throws:
IllegalStateException- if a declared role class lacks a public no-arg constructor or otherwise fails to instantiate- Since:
- 0.11.0
-
getCommunication
Extracts communication configuration as runtime model.- Returns:
- Communication model, or default if not configured
-
generateDID
Generates the full DID string for the agent, delegating the default substitution toDIDConfig.toDid(String)so the annotation and builder paths produce identical DIDs.A fixed
did.agentIdis an identity, so it is not inherited: a class that takes its@AgentSpecfrom a superclass naming a non-emptyagentIdis refused, even when it is the only subclass. A class that wants a fixed DID declares it on its own@AgentSpec.- Parameters:
agentId- fallback agent ID if not specified in annotation- Returns:
- DID string (e.g., "did:wba:example.com:agent-1")
- Throws:
IllegalStateException- if the class inherits a fixeddid.agentId
-
getGroupSpec
Extracts group membership configuration from @AgentSpec.groups.- Returns:
- GroupMemberSpec if groups are configured, or empty config
-
hasGroupSpec
public boolean hasGroupSpec()Checks if the agent has group membership configured.- Returns:
- true if groups are configured
-
extractGroupSpec
Static method to extract group configuration from an agent class.- Parameters:
agentClass- the agent class- Returns:
- GroupMemberSpec if configured
-
getMemorySpec
Extracts memory configuration from @AgentSpec.memory.- Returns:
- MemorySpec annotation or null if not configured
-
hasMemorySpec
public boolean hasMemorySpec()Checks if the agent has memory configuration.Compares every declared
MemorySpecmember against its annotation default reflectively (TAN-5039), so newly added members are covered automatically — an all-defaults@MemorySpec()still returnsfalseand does not shadow the Priority-4 template-method path.- Returns:
- true if memory is configured (any non-default value)
-
extractMemorySpec
Static method to extract memory configuration from an agent class.- Parameters:
agentClass- the agent class- Returns:
- MemorySpec if configured
-
extractMaxContextTokens
Static accessor for the agent-level context-token budget from@AgentSpec.maxContextTokens(TNS-609).- Parameters:
agentClass- the agent class- Returns:
- max context tokens (0 = no
@AgentSpecor unset)
-
extractToolCallFilter
Static accessor for the declarativeToolCallFilterfrom@AgentSpec.toolCallFilter(TNS-611). Returnsnullwhen no declarative filter is configured (the default sentinelAllowAllToolFilteris treated as "not set").- Parameters:
agentClass- the agent class- Returns:
- an instantiated filter, or
null
-
getKnowledgeEntries
Knowledge declared on@AgentSpec.knowledge(), each entry with its resolveduse, budget and search settings.The class configuration of
@AgentSpec.config()overrides and adds to them, so an agent may declare knowledge in its file alone. Empty when the annotation is absent or neither declares knowledge. Duplicate names fail initialization.- Returns:
- the declared entries, in declaration order
- Since:
- 0.18.0
-
getKnowledgeSources
Action-level sources declared on@AgentSpec.knowledge().Empty when the annotation is absent or
knowledgeis empty. Duplicate names fail initialization.- Returns:
- normalized source configurations
- Since:
- 0.14.0
-
getRetrieval
Search settings of the@AgentSpec.knowledge()entries searched together, merged field by field. MEMORY knowledge is searched apart from the other SEARCH knowledge, so when chat searches a MEMORY entry beside other SEARCH entries these are the settings of the entries other than MEMORY; the MEMORY entry's binding carries its own.Empty when no entry's
useis SEARCH.- Returns:
- normalized retrieval configuration
- Since:
- 0.14.0
- See Also:
-
extractKnowledgeSources
Static accessor forgetKnowledgeSources().- Parameters:
agentClass- the agent class- Returns:
- normalized source configurations
- Since:
- 0.14.0
-
extractRetrieval
Static accessor forgetRetrieval().- Parameters:
agentClass- the agent class- Returns:
- normalized retrieval configuration
- Since:
- 0.14.0
-
getKnowledgeSource
Resolves a named knowledge source declared on the Agent class and normalizes it to the canonical runtime model.- Parameters:
name- the declared source name- Returns:
- the normalized source configuration, or empty
- Since:
- 0.13.0
-