[ENH] Support overlapping hierarchies by allowing agents to belong to multiple MetaAgents
What's the problem this feature will solve?
Currently, the MetaAgent implementation uses a single reference: agent.meta_agent = self. This creates a 1-to-1 relationship between a constituent agent and its meta-agent. The current implementation overwrites previous meta-agent references, making overlapping hierarchies impossible to model.
Describe the solution you'd like
I would like to transition agent.meta_agent from a single object reference to a set.
- In
MetaAgent.__init__andadd_constituting_agents, the logic should append the meta agent to this set. - The
remove_constituting_agentsmethod should use discard on the set. - This ensures that an agent can be tracked by multiple higher-level entities without losing references.
Additional context
This addresses the # TODO: Make a set for meta_agents found in mesa/meta.py.
@EwoutH @quaquel I would like to work on this. Am I good to go?
@tpike3 is the designer of meta agents.
@EwoutH, we will wait for their say on this.
Hi — I’ve been looking into MetaAgent and the TODO in mesa/meta.py.
Supporting overlapping hierarchies via agent.meta_agents: set makes sense conceptually. Before starting, I just want to confirm whether there are any existing assumptions in activation/scheduling that rely on a strict 1-to-1 relationship.
If the intended direction is to allow true multi-membership, I’d be happy to take this on and include tests to ensure no regressions.