Skip to content

Commit f9d64b9

Browse files
committed
Updates
- increase test coverage - fix pre-commit issues
1 parent f732051 commit f9d64b9

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

mesa/experimental/meta_agents/meta_agent.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
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
44
create agents that contain other agents as components.
55
66
Helper methods:
77
1 - find_combinations: Find combinations of agents to create a meta-agent
88
subset.
99
2- 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
1216
Meta-Agent class (MetaAgent): An agent that contains other agents
1317
as 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

1823
import itertools
@@ -103,8 +108,7 @@ def find_combinations(
103108

104109

105110
def 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

tests/test_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,6 @@ def test_warehouse_model(): # noqa: D103
130130

131131
model = WarehouseModel(seed=42)
132132

133-
for _i in range(10):
133+
# More steps needed to hit coverage difference
134+
for _i in range(30):
134135
model.step()

0 commit comments

Comments
 (0)