Skip to content

Commit 64ccdc9

Browse files
committed
[improvement][merge-router-tests][merge multi agent router test
files][improvement][merge-litellm-tests][merge litellm wrapper test files]
1 parent f962f78 commit 64ccdc9

4 files changed

Lines changed: 184 additions & 330 deletions

File tree

tests/structs/test_multi_agent_orchestrator.py

Lines changed: 0 additions & 219 deletions
This file was deleted.

tests/structs/test_multi_agent_router.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
import os
2+
13
import pytest
24

35
from swarms.structs.agent import Agent
46
from swarms.structs.multi_agent_router import MultiAgentRouter
57

68

9+
def _minimal_agents():
10+
"""Lightweight agents for tests that don't need a real LLM call."""
11+
return [
12+
Agent(
13+
agent_name="Agent1",
14+
agent_description="Test Agent1",
15+
system_prompt="You are Agent1",
16+
model_name="openai/gpt-4o",
17+
max_loops=1,
18+
verbose=False,
19+
print_on=False,
20+
),
21+
Agent(
22+
agent_name="Agent2",
23+
agent_description="Test Agent2",
24+
system_prompt="You are Agent2",
25+
model_name="openai/gpt-4o",
26+
max_loops=1,
27+
verbose=False,
28+
print_on=False,
29+
),
30+
]
31+
32+
733
# Test fixtures
834
def real_agents():
935
"""Create real agents for testing"""
@@ -349,5 +375,59 @@ def test_concurrent_large_batch_processing():
349375
assert all(isinstance(result, (list, dict)) for result in results)
350376

351377

378+
# ============================================================================
379+
# BOSS SYSTEM PROMPT / DISCOVERY TESTS
380+
# ============================================================================
381+
382+
383+
def test_boss_system_prompt_contains_agent_names():
384+
"""The generated boss prompt must mention each registered agent by name."""
385+
router = MultiAgentRouter(agents=_minimal_agents())
386+
prompt = router._create_boss_system_prompt()
387+
388+
assert "Agent1" in prompt
389+
assert "Agent2" in prompt
390+
assert "You are a boss agent" in prompt
391+
392+
393+
def test_agents_dict_membership():
394+
"""router.agents is a name-keyed dict; lookups should be membership tests."""
395+
router = MultiAgentRouter(agents=_minimal_agents())
396+
assert "Agent1" in router.agents
397+
assert "NonexistentAgent" not in router.agents
398+
399+
400+
# ============================================================================
401+
# CONSTRUCTION-TIME VALIDATION
402+
# ============================================================================
403+
404+
405+
def test_missing_api_key_raises():
406+
"""MultiAgentRouter with no agents and no OPENAI_API_KEY must raise ValueError."""
407+
saved = os.environ.pop("OPENAI_API_KEY", None)
408+
try:
409+
with pytest.raises(ValueError, match="OpenAI API key"):
410+
MultiAgentRouter(agents=[])
411+
finally:
412+
if saved is not None:
413+
os.environ["OPENAI_API_KEY"] = saved
414+
415+
416+
def test_route_task_with_no_agents_raises():
417+
"""Routing with an empty agent list must raise."""
418+
if not os.getenv("OPENAI_API_KEY"):
419+
pytest.skip("OPENAI_API_KEY not set")
420+
router = MultiAgentRouter(agents=[])
421+
with pytest.raises(Exception):
422+
router.route_task("Test task")
423+
424+
425+
def test_route_task_with_empty_task_raises():
426+
"""An empty task string must raise ValueError."""
427+
router = MultiAgentRouter(agents=_minimal_agents())
428+
with pytest.raises(ValueError):
429+
router.route_task("")
430+
431+
352432
if __name__ == "__main__":
353433
pytest.main([__file__])

0 commit comments

Comments
 (0)