Skip to content

Support for Multi-Level and Overlapping Meta-Agents #3171

@falloficarus22

Description

@falloficarus22

Description

The current experimental MetaAgent implementation is limited to a single-parent hierarchy. When an agent joins a meta-agent, the relationship is stored as a scalar reference (agent.meta_agent = self), meaning an agent cannot belong to multiple groups at once (e.g., a person belonging to both a "Household" and a "Workplace").

Furthermore, the existing implementation includes redundant calls to model.register_agent and model.deregister_agent within MetaAgent methods. Since agents in Mesa are automatically registered with the model upon instantiation, these extra calls lead to KeyError crashes when an agent attempts to leave a group or join multiple overlapping hierarchies.

Proposed Solution

  1. Transition to Set-Based Membership: Refactor the relationship from agent.meta_agent to a set called agent.meta_agents. This allows for truly overlapping and multi-level simulation architectures.
  2. Backward Compatibility: Maintain agent.meta_agent as a property or dynamic attribute that updates based on the contents of the meta_agents set to avoid breaking existing prototypes.
  3. Refine Group Creation: Update the create_meta_agent helper to only merge agents into existing groups if the class name matches the requested type. This enables the creation of independent, overlapping organizational structures.
  4. Fix Registration Lifecycle: Remove redundant model registration/deregistration calls from its lifecycle to ensure stability across group membership changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions