@@ -448,6 +448,110 @@ def test_next_agent():
448
448
assert groupchat .next_agent (agent4 , [agent1 , agent2 , agent3 ]) == agent1
449
449
450
450
451
+ def test_send_intros ():
452
+ agent1 = autogen .ConversableAgent (
453
+ "alice" ,
454
+ description = "The first agent." ,
455
+ max_consecutive_auto_reply = 10 ,
456
+ human_input_mode = "NEVER" ,
457
+ llm_config = False ,
458
+ default_auto_reply = "This is alice speaking. TERMINATE" ,
459
+ )
460
+ agent2 = autogen .ConversableAgent (
461
+ "bob" ,
462
+ description = "The second agent." ,
463
+ max_consecutive_auto_reply = 10 ,
464
+ human_input_mode = "NEVER" ,
465
+ llm_config = False ,
466
+ default_auto_reply = "This is bob speaking. TERMINATE" ,
467
+ )
468
+ agent3 = autogen .ConversableAgent (
469
+ "sam" ,
470
+ description = "The third agent." ,
471
+ max_consecutive_auto_reply = 10 ,
472
+ human_input_mode = "NEVER" ,
473
+ llm_config = False ,
474
+ default_auto_reply = "This is sam speaking. TERMINATE" ,
475
+ )
476
+ agent4 = autogen .ConversableAgent (
477
+ "sally" ,
478
+ description = "The fourth agent." ,
479
+ max_consecutive_auto_reply = 10 ,
480
+ human_input_mode = "NEVER" ,
481
+ llm_config = False ,
482
+ default_auto_reply = "This is sally speaking. TERMINATE" ,
483
+ )
484
+
485
+ # Test empty is_termination_msg function
486
+ groupchat = autogen .GroupChat (
487
+ agents = [agent1 , agent2 , agent3 ],
488
+ messages = [],
489
+ speaker_selection_method = "round_robin" ,
490
+ max_round = 10 ,
491
+ send_introductions = True ,
492
+ )
493
+
494
+ intro = groupchat .introductions_msg ()
495
+ assert "The first agent." in intro
496
+ assert "The second agent." in intro
497
+ assert "The third agent." in intro
498
+ assert "The fourth agent." not in intro
499
+
500
+ intro = groupchat .introductions_msg ([agent1 , agent2 , agent4 ])
501
+ assert "The first agent." in intro
502
+ assert "The second agent." in intro
503
+ assert "The third agent." not in intro
504
+ assert "The fourth agent." in intro
505
+
506
+ groupchat = autogen .GroupChat (
507
+ agents = [agent1 , agent2 , agent3 ],
508
+ messages = [],
509
+ speaker_selection_method = "round_robin" ,
510
+ max_round = 10 ,
511
+ send_introductions = True ,
512
+ )
513
+
514
+ group_chat_manager = autogen .GroupChatManager (
515
+ groupchat = groupchat ,
516
+ llm_config = False ,
517
+ is_termination_msg = lambda x : x .get ("content" , "" ).rstrip ().find ("TERMINATE" ) >= 0 ,
518
+ )
519
+
520
+ group_chat_manager .initiate_chat (group_chat_manager , message = "The initiating message." )
521
+ for a in [agent1 , agent2 , agent3 ]:
522
+ messages = agent1 .chat_messages [group_chat_manager ]
523
+ assert len (messages ) == 3
524
+ assert "The first agent." in messages [0 ]["content" ]
525
+ assert "The second agent." in messages [0 ]["content" ]
526
+ assert "The third agent." in messages [0 ]["content" ]
527
+ assert "The initiating message." == messages [1 ]["content" ]
528
+ assert messages [2 ]["content" ] == agent1 ._default_auto_reply
529
+
530
+ # Reset and start again
531
+ agent1 .reset ()
532
+ agent2 .reset ()
533
+ agent3 .reset ()
534
+ agent4 .reset ()
535
+
536
+ # Check the default (no introductions)
537
+ groupchat2 = autogen .GroupChat (
538
+ agents = [agent1 , agent2 , agent3 ], messages = [], speaker_selection_method = "round_robin" , max_round = 10
539
+ )
540
+
541
+ group_chat_manager2 = autogen .GroupChatManager (
542
+ groupchat = groupchat2 ,
543
+ llm_config = False ,
544
+ is_termination_msg = lambda x : x .get ("content" , "" ).rstrip ().find ("TERMINATE" ) >= 0 ,
545
+ )
546
+
547
+ group_chat_manager2 .initiate_chat (group_chat_manager2 , message = "The initiating message." )
548
+ for a in [agent1 , agent2 , agent3 ]:
549
+ messages = agent1 .chat_messages [group_chat_manager2 ]
550
+ assert len (messages ) == 2
551
+ assert "The initiating message." == messages [0 ]["content" ]
552
+ assert messages [1 ]["content" ] == agent1 ._default_auto_reply
553
+
554
+
451
555
def test_selection_helpers ():
452
556
agent1 = autogen .ConversableAgent (
453
557
"alice" ,
@@ -814,6 +918,7 @@ def chat(gc_manager: autogen.GroupChatManager):
814
918
# test_agent_mentions()
815
919
# test_termination()
816
920
# test_next_agent()
921
+ test_send_intros ()
817
922
# test_invalid_allow_repeat_speaker()
818
923
# test_graceful_exit_before_max_round()
819
- test_clear_agents_history ()
924
+ # test_clear_agents_history()
0 commit comments