@@ -451,6 +451,82 @@ def test_swarm_auto_completion_without_handoff():
451451 no_handoff_agent .invoke_async .assert_called ()
452452
453453
454+ def test_swarm_configurable_entry_point ():
455+ """Test swarm with configurable entry point."""
456+ # Create multiple agents
457+ agent1 = create_mock_agent ("agent1" , "Agent 1 response" )
458+ agent2 = create_mock_agent ("agent2" , "Agent 2 response" )
459+ agent3 = create_mock_agent ("agent3" , "Agent 3 response" )
460+
461+ # Create swarm with agent2 as entry point
462+ swarm = Swarm ([agent1 , agent2 , agent3 ], entry_point = agent2 )
463+
464+ # Verify entry point is set correctly
465+ assert swarm .entry_point is agent2
466+
467+ # Execute swarm
468+ result = swarm ("Test task" )
469+
470+ # Verify agent2 was the first to execute
471+ assert result .status == Status .COMPLETED
472+ assert len (result .node_history ) == 1
473+ assert result .node_history [0 ].node_id == "agent2"
474+
475+
476+ def test_swarm_invalid_entry_point ():
477+ """Test swarm with invalid entry point raises error."""
478+ agent1 = create_mock_agent ("agent1" , "Agent 1 response" )
479+ agent2 = create_mock_agent ("agent2" , "Agent 2 response" )
480+ agent3 = create_mock_agent ("agent3" , "Agent 3 response" ) # Not in swarm
481+
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 )
485+
486+
487+ def test_swarm_default_entry_point ():
488+ """Test swarm uses first agent as default entry point."""
489+ agent1 = create_mock_agent ("agent1" , "Agent 1 response" )
490+ agent2 = create_mock_agent ("agent2" , "Agent 2 response" )
491+
492+ # Create swarm without specifying entry point
493+ swarm = Swarm ([agent1 , agent2 ])
494+
495+ # Verify no explicit entry point is set
496+ assert swarm .entry_point is None
497+
498+ # Execute swarm
499+ result = swarm ("Test task" )
500+
501+ # Verify first agent was used as entry point
502+ assert result .status == Status .COMPLETED
503+ assert len (result .node_history ) == 1
504+ assert result .node_history [0 ].node_id == "agent1"
505+
506+
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+
454530def test_swarm_validate_unsupported_features ():
455531 """Test Swarm validation for session persistence and callbacks."""
456532 # Test with normal agent (should work)
0 commit comments