Skip to content

Commit a193a8e

Browse files
authored
fix(majority-voting): validate agents and loop count (kyegomez#1955)
1 parent 9bd9354 commit a193a8e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

swarms/structs/majority_voting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ def __init__(
163163

164164
def reliability_check(self):
165165

166-
if self.agents is None:
167-
raise ValueError("Agents list is empty")
166+
if not self.agents:
167+
raise ValueError("Agents list cannot be None or empty")
168+
169+
if self.max_loops <= 0:
170+
raise ValueError("max_loops must be greater than 0")
168171

169172
# Log the agents in a more formatted, readable way
170173
agent_list = "\n".join(

tests/structs/test_majority_voting.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def test_majority_voting_error_handling():
174174
except ValueError as e:
175175
assert "max_loops" in str(e).lower() or "0" in str(e)
176176

177+
try:
178+
MajorityVoting(agents=[analyst], max_loops=-1)
179+
assert (
180+
False
181+
), "Should have raised ValueError for negative max_loops"
182+
except ValueError as e:
183+
assert "max_loops" in str(e).lower()
184+
177185

178186
def test_majority_voting_different_output_types():
179187
"""Test MajorityVoting with different output types"""

0 commit comments

Comments
 (0)