Record Class GroupMemberSpec

java.lang.Object
java.lang.Record
com.tnsai.agents.groups.GroupMemberSpec
Record Components:
groups - Group IDs this agent belongs to
autoJoin - Whether to automatically join groups on agent start
autoCreateGroups - Whether to create groups if they don't exist
role - 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 Details

    • GroupMemberSpec

      public GroupMemberSpec(List<String> groups, boolean autoJoin, boolean autoCreateGroups, String role, int priority, int maxConcurrentTasks)
      Creates an instance of a GroupMemberSpec record class.
      Parameters:
      groups - the value for the groups record component
      autoJoin - the value for the autoJoin record component
      autoCreateGroups - the value for the autoCreateGroups record component
      role - the value for the role record component
      priority - the value for the priority record component
      maxConcurrentTasks - the value for the maxConcurrentTasks record component
  • Method Details

    • from

      public static GroupMemberSpec from(GroupMember annotation)
      Creates a GroupMemberSpec from a GroupMember annotation.
      Parameters:
      annotation - the GroupMember annotation
      Returns:
      configuration extracted from the annotation
      Throws:
      IllegalArgumentException - if annotation is null
    • empty

      public static GroupMemberSpec empty()
      Creates an empty configuration (no groups).
      Returns:
      empty configuration
    • of

      public static GroupMemberSpec of(String... groups)
      Creates a configuration that auto-joins the given groups with the default member role. Mirrors empty() but with the supplied group list — the common programmatic case for AgentBuilder.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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • groups

      public List<String> groups()
      Returns the value of the groups record component.
      Returns:
      the value of the groups record component
    • autoJoin

      public boolean autoJoin()
      Returns the value of the autoJoin record component.
      Returns:
      the value of the autoJoin record component
    • autoCreateGroups

      public boolean autoCreateGroups()
      Returns the value of the autoCreateGroups record component.
      Returns:
      the value of the autoCreateGroups record component
    • role

      public String role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • priority

      public int priority()
      Returns the value of the priority record component.
      Returns:
      the value of the priority record component
    • maxConcurrentTasks

      public int maxConcurrentTasks()
      Returns the value of the maxConcurrentTasks record component.
      Returns:
      the value of the maxConcurrentTasks record component