Skip to content

Commit e83ed4a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 067dbaf commit e83ed4a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

mesa_llm/parallel_stepping.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def step_agents_parallel_sync(agents: list[Agent | LLMAgent]) -> None:
8585
_original_shuffle_do = AgentSet.shuffle_do
8686
try:
8787
from mesa.agentset import _HardKeyAgentSet
88+
8889
_original_hardkey_shuffle_do = _HardKeyAgentSet.shuffle_do
8990
except ImportError:
9091
_HardKeyAgentSet = None
@@ -98,7 +99,7 @@ def _enhanced_shuffle_do(self, method: str, *args, **kwargs):
9899
if hasattr(agent, "model") and getattr(agent.model, "parallel_stepping", False):
99100
step_agents_parallel_sync(list(self))
100101
return
101-
102+
102103
if _HardKeyAgentSet and isinstance(self, _HardKeyAgentSet):
103104
_original_hardkey_shuffle_do(self, method, *args, **kwargs)
104105
else:

tests/test_parallel_stepping.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44
from mesa.agent import Agent, AgentSet
5-
from mesa.model import Model
65
from mesa.experimental.meta_agents.meta_agent import MetaAgent
6+
from mesa.model import Model
77

88
from mesa_llm.parallel_stepping import (
99
disable_automatic_parallel_stepping,
@@ -100,6 +100,8 @@ async def wrapper():
100100
asyncio.run(wrapper())
101101
assert a1.counter == 1
102102
assert a2.counter == 1
103+
104+
103105
@pytest.fixture(autouse=True)
104106
def manage_parallel_stepping_patch():
105107
# Helper to clean up parallel stepping state if tests fail
@@ -109,6 +111,7 @@ def manage_parallel_stepping_patch():
109111

110112
# --- Meta Agent Parallel Conflict Tests ---
111113

114+
112115
class ConflictWorker(Agent):
113116
def __init__(self, model):
114117
super().__init__(model)
@@ -143,10 +146,10 @@ def test_meta_agent_parallel_conflict_fix():
143146
"""
144147
enable_automatic_parallel_stepping("asyncio")
145148
model = ConflictBusinessModel()
146-
149+
147150
# Run one step
148151
model.step()
149-
152+
150153
# Assert worker was only stepped once
151154
# If the fix failed, this would be 2
152155
assert model.worker.step_count == 1
@@ -156,25 +159,25 @@ def test_meta_agent_multithreaded_conflict_fix():
156159
"""Test same logic but with multithreaded mode."""
157160
disable_automatic_parallel_stepping()
158161
enable_automatic_parallel_stepping("threading")
159-
162+
160163
model = ConflictBusinessModel()
161164
model.step()
162-
165+
163166
assert model.worker.step_count == 1
164167

165168

166169
def test_agent_becomes_independent_again():
167170
"""Test that an agent removed from MetaAgent is stepped by scheduler again."""
168171
enable_automatic_parallel_stepping("asyncio")
169172
model = ConflictBusinessModel()
170-
173+
171174
# 1. Initially it's a component
172175
assert model.worker.is_component is True
173-
176+
174177
# 2. Remove it from manager
175178
model.manager.remove_constituting_agents({model.worker})
176179
assert model.worker.is_component is False
177-
180+
178181
# 3. Model step should now step the worker directly
179182
model.step()
180183
assert model.worker.step_count == 1

0 commit comments

Comments
 (0)