Package com.tnsai.agents.groups
Record Class GroupMemberSpec
java.lang.Object
java.lang.Record
com.tnsai.agents.groups.GroupMemberSpec
- Record Components:
groups- Group IDs this agent belongs toautoJoin- Whether to automatically join groups on agent startautoCreateGroups- Whether to create groups if they don't existrole- Role within groups (e.g., "leader", "worker", "observer")priority- Priority for task assignment within groups (higher = more likely)maxConcurrentTasks- Maximum concurrent tasks from group assignments
public record GroupMemberSpec(List<String> groups, boolean autoJoin, boolean autoCreateGroups, String role, int priority, int maxConcurrentTasks)
extends Record
Configuration record for group membership extracted from
GroupMember annotation.
This record provides a typed, immutable representation of group membership configuration, making it easy to work with annotation values at runtime.
Usage Example
// Extract from annotation
GroupMemberSpec config = GroupMemberSpec.from(groupMemberAnnotation);
// Check configuration
if (config.autoJoin()) {
for (String groupId : config.groups()) {
AgentGroup group = config.autoCreateGroups()
? GroupRegistry.getInstance().getOrCreate(groupId)
: GroupRegistry.getInstance().get(groupId).orElse(null);
if (group != null) {
group.addMember(agent);
}
}
}
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGroupMemberSpec(List<String> groups, boolean autoJoin, boolean autoCreateGroups, String role, int priority, int maxConcurrentTasks) Creates an instance of aGroupMemberSpecrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of theautoCreateGroupsrecord component.booleanautoJoin()Returns the value of theautoJoinrecord component.static GroupMemberSpecempty()Creates an empty configuration (no groups).final booleanIndicates whether some other object is "equal to" this one.static GroupMemberSpecfrom(GroupMember annotation) Creates a GroupMemberSpec from aGroupMemberannotation.groups()Returns the value of thegroupsrecord component.booleanChecks if this configuration has any groups defined.final inthashCode()Returns a hash code value for this object.booleanisLeader()Checks if this agent should be considered a leader in groups.booleanChecks if this agent is an observer (read-only member).intReturns the value of themaxConcurrentTasksrecord component.static GroupMemberSpecCreates a configuration that auto-joins the given groups with the default member role.intpriority()Returns the value of thepriorityrecord component.role()Returns the value of therolerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
GroupMemberSpec
public GroupMemberSpec(List<String> groups, boolean autoJoin, boolean autoCreateGroups, String role, int priority, int maxConcurrentTasks) Creates an instance of aGroupMemberSpecrecord class.- Parameters:
groups- the value for thegroupsrecord componentautoJoin- the value for theautoJoinrecord componentautoCreateGroups- the value for theautoCreateGroupsrecord componentrole- the value for therolerecord componentpriority- the value for thepriorityrecord componentmaxConcurrentTasks- the value for themaxConcurrentTasksrecord component
-
-
Method Details
-
from
Creates a GroupMemberSpec from aGroupMemberannotation.- Parameters:
annotation- the GroupMember annotation- Returns:
- configuration extracted from the annotation
- Throws:
IllegalArgumentException- if annotation is null
-
empty
Creates an empty configuration (no groups).- Returns:
- empty configuration
-
of
Creates a configuration that auto-joins the given groups with the default member role. Mirrorsempty()but with the supplied group list — the common programmatic case forAgentBuilder.groupMembership(GroupMemberSpec).- Parameters:
groups- groups to auto-join (auto-create disabled)- Returns:
- configuration joining
groups
-
hasGroups
public boolean hasGroups()Checks if this configuration has any groups defined.- Returns:
- true if at least one group is defined
-
isLeader
public boolean isLeader()Checks if this agent should be considered a leader in groups.- Returns:
- true if role is "leader"
-
isObserver
public boolean isObserver()Checks if this agent is an observer (read-only member).- Returns:
- true if role is "observer"
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
groups
Returns the value of thegroupsrecord component.- Returns:
- the value of the
groupsrecord component
-
autoJoin
public boolean autoJoin()Returns the value of theautoJoinrecord component.- Returns:
- the value of the
autoJoinrecord component
-
autoCreateGroups
public boolean autoCreateGroups()Returns the value of theautoCreateGroupsrecord component.- Returns:
- the value of the
autoCreateGroupsrecord component
-
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
priority
public int priority()Returns the value of thepriorityrecord component.- Returns:
- the value of the
priorityrecord component
-
maxConcurrentTasks
public int maxConcurrentTasks()Returns the value of themaxConcurrentTasksrecord component.- Returns:
- the value of the
maxConcurrentTasksrecord component
-