@@ -459,10 +459,10 @@ def test_swarm_configurable_entry_point():
459459 agent3 = create_mock_agent ("agent3" , "Agent 3 response" )
460460
461461 # Create swarm with agent2 as entry point
462- swarm = Swarm ([agent1 , agent2 , agent3 ], entry_point = " agent2" )
462+ swarm = Swarm ([agent1 , agent2 , agent3 ], entry_point = agent2 )
463463
464464 # Verify entry point is set correctly
465- assert swarm .entry_point == " agent2"
465+ assert swarm .entry_point is agent2
466466
467467 # Execute swarm
468468 result = swarm ("Test task" )
@@ -477,14 +477,11 @@ def test_swarm_invalid_entry_point():
477477 """Test swarm with invalid entry point raises error."""
478478 agent1 = create_mock_agent ("agent1" , "Agent 1 response" )
479479 agent2 = create_mock_agent ("agent2" , "Agent 2 response" )
480+ agent3 = create_mock_agent ("agent3" , "Agent 3 response" ) # Not in swarm
480481
481- # Try to create swarm with non-existent entry point
482- with pytest .raises (ValueError , match = "Entry point 'nonexistent' not found in swarm nodes" ):
483- Swarm ([agent1 , agent2 ], entry_point = "nonexistent" )
484-
485- # Try with random string entry point
486- with pytest .raises (ValueError , match = "Entry point 'xyz123random' not found in swarm nodes" ):
487- Swarm ([agent1 , agent2 ], entry_point = "xyz123random" )
482+ # Try to create swarm with agent not in the swarm
483+ with pytest .raises (ValueError , match = "Entry point agent not found in swarm nodes" ):
484+ Swarm ([agent1 , agent2 ], entry_point = agent3 )
488485
489486
490487def test_swarm_default_entry_point ():
@@ -507,6 +504,29 @@ def test_swarm_default_entry_point():
507504 assert result .node_history [0 ].node_id == "agent1"
508505
509506
507+ def test_swarm_duplicate_agent_names ():
508+ """Test swarm rejects agents with duplicate names."""
509+ agent1 = create_mock_agent ("duplicate_name" , "Agent 1 response" )
510+ agent2 = create_mock_agent ("duplicate_name" , "Agent 2 response" )
511+
512+ # Try to create swarm with duplicate names
513+ with pytest .raises (ValueError , match = "Node ID 'duplicate_name' is not unique" ):
514+ Swarm ([agent1 , agent2 ])
515+
516+
517+ def test_swarm_entry_point_same_name_different_object ():
518+ """Test entry point validation with same name but different object."""
519+ agent1 = create_mock_agent ("agent1" , "Agent 1 response" )
520+ agent2 = create_mock_agent ("agent2" , "Agent 2 response" )
521+
522+ # Create a different agent with same name as agent1
523+ different_agent_same_name = create_mock_agent ("agent1" , "Different agent response" )
524+
525+ # Try to use the different agent as entry point
526+ with pytest .raises (ValueError , match = "Entry point agent not found in swarm nodes" ):
527+ Swarm ([agent1 , agent2 ], entry_point = different_agent_same_name )
528+
529+
510530def test_swarm_validate_unsupported_features ():
511531 """Test Swarm validation for session persistence and callbacks."""
512532 # Test with normal agent (should work)
0 commit comments