11"""Implementation of Mesa's meta agent capability.
22
3- This contains two helper methods and a MetaAgent class that can be used to
3+ This contains four helper functions and a MetaAgent class that can be used to
44create agents that contain other agents as components.
55
66Helper methods:
771 - find_combinations: Find combinations of agents to create a meta-agent
88subset.
992- evaluate_combination: Evaluate combinations of agents by some user based
10- criteria to determine if it should be a subset.
10+ criteria to determine if it should be a subset of agents.
11+ 3- extract_class: Helper function for create_meta-agent. Extracts the types of
12+ agent being created to create a new instance of that agent type.
13+ 4- create_meta_agent: Create a new meta-agent class and instantiate
14+ agents in that class.
1115
1216Meta-Agent class (MetaAgent): An agent that contains other agents
1317as components.
1418
15- See basic examples >> meta_agents for dynamic creation and explicit creation
19+ See basic examples >> meta_agents for deliberate meta-agent creation (warehouse)
20+ and emergent meta-agent creation (alliance formation) of meta-agents.
1621"""
1722
1823import itertools
@@ -103,8 +108,7 @@ def find_combinations(
103108
104109
105110def extract_class (agents_by_type : dict , new_agent_class : str ):
106- """Helper function for create_meta_agents extracts the type of agent
107- being created to create a new instance of that agent type.
111+ """Helper function for create_meta_agents extracts the types of agents.
108112
109113 Args:
110114 agents_by_type (dict): The dictionary of agents by type.
@@ -129,8 +133,7 @@ def create_meta_agent(
129133 assume_subagent_methods : bool = False ,
130134 assume_subagent_attributes : bool = False ,
131135) -> Any | None :
132- """Dynamically create a new meta-agent class and instantiate agents
133- in that class.
136+ """Create a new meta-agent class and instantiate agents.
134137
135138 Parameters:
136139 model (Any): The model instance.
@@ -317,7 +320,7 @@ def get_subagent_instance(self, agent_type) -> set[type]:
317320 try :
318321 return self .subagents_by_type [agent_type ][0 ]
319322 except KeyError :
320- raise ValueError (f"No subagent of type { agent_type } found." )
323+ raise ValueError (f"No subagent of type { agent_type } found." ) from None
321324
322325 def add_subagents (
323326 self ,
@@ -344,14 +347,6 @@ def remove_subagents(self, remove_agents: set[Agent]):
344347 agent .meta_agent = None # TODO: Remove meta_agent from set
345348 self .model .deregister_agent (agent )
346349
347- def get_subagent_type (self ) -> set [type ]:
348- """Get the types of all subagents.
349-
350- Returns:
351- set[type]: A set of unique types of the subagents.
352- """
353- return {type (agent ) for agent in self ._subset }
354-
355350 def step (self ):
356351 """Perform the agent's step.
357352
0 commit comments