@@ -598,24 +598,25 @@ def test_chain_with_different_combination_instructions(self):
598
598
599
599
def test_set_all_individual_agent_combination_instructions (self ):
600
600
"""Set custom combo insts for all agents"""
601
+
601
602
task = "Generate argument for or against social media in 10 words."
602
603
agent1 = Agent (
603
604
task = task ,
604
605
combination_instructions = "Build on previous ideas: ${previous_responses}" ,
605
606
model = "gpt-3.5-turbo" ,
606
- kwargs = {"max_tokens" : 30 }
607
+ kwargs = {"max_tokens" : 30 },
607
608
)
608
609
agent2 = Agent (
609
610
task = task ,
610
611
combination_instructions = "Critique previous points: ${previous_responses}" ,
611
612
model = "gpt-3.5-turbo" ,
612
- kwargs = {"max_tokens" : 30 }
613
+ kwargs = {"max_tokens" : 30 },
613
614
)
614
615
agent3 = Agent (
615
616
task = task ,
616
617
combination_instructions = "Synthesize all points: ${previous_responses}" ,
617
618
model = "gpt-3.5-turbo" ,
618
- kwargs = {"max_tokens" : 30 }
619
+ kwargs = {"max_tokens" : 30 },
619
620
)
620
621
621
622
chain = Chain ([agent1 , agent2 , agent3 ], task = task )
@@ -636,87 +637,71 @@ def test_set_all_individual_agent_combination_instructions(self):
636
637
637
638
self .assertEqual (3 , len (chain .responses ))
638
639
640
+ self .assertIn ("Critique previous points:" , agent2 .prompts [0 ]["user" ])
641
+ self .assertIn ("Synthesize all points:" , agent3 .prompts [0 ]["user" ])
642
+
639
643
def test_set_some_individual_agent_combination_instructions (self ):
640
- """When combo insts set for some Agents, we use the set instructions for the relevant Agents
641
- and structure combo instructions for other Agents"""
644
+ """When combo insts set for some Agents, we use the set instructions for the relevant Agents and structure combo instructions for other Agents"""
642
645
task = "Generate argument for or against social media in 10 words."
643
646
agent1 = Agent (
644
647
task = task ,
645
648
combination_instructions = "Expand on previous responses: ${previous_responses}" ,
646
649
model = "gpt-3.5-turbo" ,
647
- kwargs = {"max_tokens" : 30 }
650
+ kwargs = {"max_tokens" : 30 },
648
651
)
649
652
agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
650
653
agent3 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
651
654
652
- chain = Chain ([agent1 , agent2 , agent3 ], task = task , combination_instructions = "chain" )
655
+ chain = Chain (
656
+ [agent1 , agent2 , agent3 ], task = task , combination_instructions = "jury"
657
+ )
653
658
chain .process ()
654
659
655
660
self .assertEqual (
656
661
"Expand on previous responses: ${previous_responses}" ,
657
662
agent1 .combination_instructions ,
658
663
)
659
664
self .assertEqual (
660
- DEFAULTS [' combination_instructions' ][ 'chain' ],
665
+ DEFAULTS [" combination_instructions" ][ "jury" ],
661
666
agent2 .combination_instructions ,
662
667
)
663
668
self .assertEqual (
664
- DEFAULTS [' combination_instructions' ][ 'chain' ],
669
+ DEFAULTS [" combination_instructions" ][ "jury" ],
665
670
agent3 .combination_instructions ,
666
671
)
667
672
668
673
self .assertEqual (3 , len (chain .responses ))
669
674
675
+ self .assertIn ("Reexamine your views" , agent2 .prompts [0 ]["user" ])
676
+ self .assertIn ("Reexamine your views" , agent3 .prompts [0 ]["user" ])
677
+
670
678
def test_no_individual_agent_combination_instructions (self ):
671
679
"""Make sure when no combo inst set, but set in structure, Agents get what is set in structure"""
672
680
task = "Generate argument for or against social media in 10 words."
673
681
agent1 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
674
682
agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
675
683
agent3 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
676
684
677
- chain = Chain ([agent1 , agent2 , agent3 ], task = task , combination_instructions = "first_wave" )
678
- chain .process ()
679
-
680
- self .assertEqual (
681
- DEFAULTS ['combination_instructions' ]['first_wave' ],
682
- agent1 .combination_instructions ,
683
- )
684
- self .assertEqual (
685
- DEFAULTS ['combination_instructions' ]['first_wave' ],
686
- agent2 .combination_instructions ,
687
- )
688
- self .assertEqual (
689
- DEFAULTS ['combination_instructions' ]['first_wave' ],
690
- agent3 .combination_instructions ,
685
+ chain = Chain (
686
+ [agent1 , agent2 , agent3 ], task = task , combination_instructions = "first_wave"
691
687
)
692
-
693
- self .assertEqual (3 , len (chain .responses ))
694
-
695
- def test_no_individual_agent_combination_instructions_default (self ):
696
- """Make sure when no combo inst set every Agent gets default"""
697
- task = "Generate argument for or against social media in 10 words."
698
- agent1 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
699
- agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
700
- agent3 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
701
-
702
- chain = Chain ([agent1 , agent2 , agent3 ], task = task )
703
688
chain .process ()
704
689
705
690
self .assertEqual (
706
- DEFAULTS [' combination_instructions' ][ 'default' ],
691
+ DEFAULTS [" combination_instructions" ][ "first_wave" ],
707
692
agent1 .combination_instructions ,
708
693
)
709
694
self .assertEqual (
710
- DEFAULTS [' combination_instructions' ][ 'default' ],
695
+ DEFAULTS [" combination_instructions" ][ "first_wave" ],
711
696
agent2 .combination_instructions ,
712
697
)
713
698
self .assertEqual (
714
- DEFAULTS [' combination_instructions' ][ 'default' ],
699
+ DEFAULTS [" combination_instructions" ][ "first_wave" ],
715
700
agent3 .combination_instructions ,
716
701
)
717
702
718
- self .assertEqual ( 3 , len ( chain . responses ) )
719
-
703
+ self .assertIn ( "Respect each other’s viewpoints" , agent2 . prompts [ 0 ][ "user" ] )
704
+ self . assertIn ( "Respect each other’s viewpoints" , agent3 . prompts [ 0 ][ "user" ])
720
705
721
706
def test_chain_debate_instructions (self ):
722
707
a2 = Agent (ideology = "moderate" , model = self .model )
@@ -1038,21 +1023,20 @@ def test_debate_with_different_combination_instructions(self):
1038
1023
1039
1024
self .assertIn ("Counter the previous point:" , agent2 .prompts [0 ]["user" ])
1040
1025
1041
-
1042
1026
def test_set_all_individual_agent_combination_instructions (self ):
1043
1027
"""Set custom combo insts for all agents"""
1044
1028
task = "Generate argument for or against social media in 10 words."
1045
1029
agent1 = Agent (
1046
1030
task = task ,
1047
1031
combination_instructions = "Respond to previous argument: ${previous_responses}" ,
1048
1032
model = "gpt-3.5-turbo" ,
1049
- kwargs = {"max_tokens" : 30 }
1033
+ kwargs = {"max_tokens" : 30 },
1050
1034
)
1051
1035
agent2 = Agent (
1052
1036
task = task ,
1053
1037
combination_instructions = "Counter the previous point: ${previous_responses}" ,
1054
1038
model = "gpt-3.5-turbo" ,
1055
- kwargs = {"max_tokens" : 30 }
1039
+ kwargs = {"max_tokens" : 30 },
1056
1040
)
1057
1041
1058
1042
debate = Debate ([agent1 , agent2 ], task = task )
@@ -1067,7 +1051,7 @@ def test_set_all_individual_agent_combination_instructions(self):
1067
1051
"Counter the previous point: ${previous_responses}" ,
1068
1052
)
1069
1053
1070
- self .assertEqual ( len ( debate . responses ), 2 )
1054
+ self .assertNotIn ( "${previous_responses}" , agent2 . prompts [ 0 ][ "user" ] )
1071
1055
1072
1056
self .assertIn ("Counter the previous point:" , agent2 .prompts [0 ]["user" ])
1073
1057
@@ -1079,7 +1063,7 @@ def test_set_some_individual_agent_combination_instructions(self):
1079
1063
task = task ,
1080
1064
combination_instructions = "Address the previous point: ${previous_responses}" ,
1081
1065
model = "gpt-3.5-turbo" ,
1082
- kwargs = {"max_tokens" : 30 }
1066
+ kwargs = {"max_tokens" : 30 },
1083
1067
)
1084
1068
agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
1085
1069
@@ -1090,23 +1074,37 @@ def test_set_some_individual_agent_combination_instructions(self):
1090
1074
"Address the previous point: ${previous_responses}" ,
1091
1075
agent1 .combination_instructions ,
1092
1076
)
1093
- self .assertEqual (DEFAULTS ['combination_instructions' ]['debate' ], agent2 .combination_instructions )
1094
-
1095
- self .assertEqual (len (debate .responses ), 2 )
1077
+ self .assertEqual (
1078
+ DEFAULTS ["combination_instructions" ]["debate" ],
1079
+ agent2 .combination_instructions ,
1080
+ )
1081
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1082
+ self .assertIn ("in the third person" , agent2 .prompts [0 ]["user" ])
1096
1083
1097
1084
def test_no_individual_agent_combination_instructions (self ):
1098
1085
"""Make sure when no combo inst set, but set in structure, Agents get what is set in structure"""
1099
1086
task = "Generate argument for or against social media in 10 words."
1100
1087
agent1 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
1101
1088
agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
1102
1089
1103
- debate = Debate ([agent1 , agent2 ], task = task , combination_instructions = "first_wave" )
1090
+ debate = Debate (
1091
+ [agent1 , agent2 ], task = task , combination_instructions = "first_wave"
1092
+ )
1104
1093
debate .process ()
1105
1094
1106
- self .assertEqual (DEFAULTS ['combination_instructions' ]['first_wave' ], agent1 .combination_instructions )
1107
- self .assertEqual (DEFAULTS ['combination_instructions' ]['first_wave' ], agent2 .combination_instructions )
1095
+ self .assertEqual (
1096
+ DEFAULTS ["combination_instructions" ]["first_wave" ],
1097
+ agent1 .combination_instructions ,
1098
+ )
1099
+ self .assertEqual (
1100
+ DEFAULTS ["combination_instructions" ]["first_wave" ],
1101
+ agent2 .combination_instructions ,
1102
+ )
1108
1103
1109
1104
self .assertEqual (len (debate .responses ), 2 )
1105
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1106
+
1107
+ self .assertIn ("rational-critical debate" , agent2 .prompts [0 ]["user" ])
1110
1108
1111
1109
def test_no_individual_agent_combination_instructions_default (self ):
1112
1110
"""Make sure when no combo inst set every Agent gets default"""
@@ -1117,10 +1115,18 @@ def test_no_individual_agent_combination_instructions_default(self):
1117
1115
debate = Debate ([agent1 , agent2 ], task = task )
1118
1116
debate .process ()
1119
1117
1120
- self .assertEqual (DEFAULTS ['combination_instructions' ]['debate' ], agent1 .combination_instructions )
1121
- self .assertEqual (DEFAULTS ['combination_instructions' ]['debate' ], agent2 .combination_instructions )
1118
+ self .assertEqual (
1119
+ DEFAULTS ["combination_instructions" ]["debate" ],
1120
+ agent1 .combination_instructions ,
1121
+ )
1122
+ self .assertEqual (
1123
+ DEFAULTS ["combination_instructions" ]["debate" ],
1124
+ agent2 .combination_instructions ,
1125
+ )
1126
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1122
1127
1123
1128
self .assertEqual (len (debate .responses ), 2 )
1129
+ self .assertIn ("third person" , agent2 .prompts [0 ]["user" ])
1124
1130
1125
1131
1126
1132
class TestAgentStructures (unittest .TestCase ):
@@ -1306,6 +1312,8 @@ def test_graph_with_different_combination_instructions(self):
1306
1312
self .assertIn ("Prev2 to previous" , agent2 .prompts [0 ]["user" ])
1307
1313
self .assertIn ("Greetings to previous" , agent3 .prompts [0 ]["user" ])
1308
1314
1315
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1316
+ self .assertNotIn ("${previous_responses}" , agent3 .prompts [0 ]["user" ])
1309
1317
1310
1318
def test_set_all_individual_agent_combination_instructions (self ):
1311
1319
"""Set custom combo insts for all agents"""
@@ -1314,19 +1322,19 @@ def test_set_all_individual_agent_combination_instructions(self):
1314
1322
task = task ,
1315
1323
combination_instructions = "Summarize previous insights: ${previous_responses}" ,
1316
1324
model = "gpt-3.5-turbo" ,
1317
- kwargs = {"max_tokens" : 30 }
1325
+ kwargs = {"max_tokens" : 30 },
1318
1326
)
1319
1327
agent2 = Agent (
1320
1328
task = task ,
1321
1329
combination_instructions = "Provide contrasting viewpoint: ${previous_responses}" ,
1322
1330
model = "gpt-3.5-turbo" ,
1323
- kwargs = {"max_tokens" : 30 }
1331
+ kwargs = {"max_tokens" : 30 },
1324
1332
)
1325
1333
agent3 = Agent (
1326
1334
task = task ,
1327
1335
combination_instructions = "Synthesize all perspectives: ${previous_responses}" ,
1328
1336
model = "gpt-3.5-turbo" ,
1329
- kwargs = {"max_tokens" : 30 }
1337
+ kwargs = {"max_tokens" : 30 },
1330
1338
)
1331
1339
1332
1340
agents = {"agent1" : agent1 , "agent2" : agent2 , "agent3" : agent3 }
@@ -1348,6 +1356,10 @@ def test_set_all_individual_agent_combination_instructions(self):
1348
1356
agent3 .combination_instructions ,
1349
1357
)
1350
1358
1359
+ self .assertIn ("Provide contrasting viewpoint:" , agent2 .prompts [0 ]["user" ])
1360
+ self .assertIn ("Synthesize all perspectives:" , agent3 .prompts [0 ]["user" ])
1361
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1362
+ self .assertNotIn ("${previous_responses}" , agent3 .prompts [0 ]["user" ])
1351
1363
self .assertEqual (3 , len (graph .responses ))
1352
1364
1353
1365
def test_set_some_individual_agent_combination_instructions (self ):
@@ -1358,30 +1370,36 @@ def test_set_some_individual_agent_combination_instructions(self):
1358
1370
task = task ,
1359
1371
combination_instructions = "Build on previous ideas: ${previous_responses}" ,
1360
1372
model = "gpt-3.5-turbo" ,
1361
- kwargs = {"max_tokens" : 30 }
1373
+ kwargs = {"max_tokens" : 30 },
1362
1374
)
1363
1375
agent2 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
1364
1376
agent3 = Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
1365
1377
1366
1378
agents = {"agent1" : agent1 , "agent2" : agent2 , "agent3" : agent3 }
1367
1379
edges = [("agent1" , "agent2" ), ("agent1" , "agent3" ), ("agent2" , "agent3" )]
1368
1380
1369
- graph = Graph (agents = agents , edges = edges , task = task , combination_instructions = "voting" )
1381
+ graph = Graph (
1382
+ agents = agents , edges = edges , task = task , combination_instructions = "voting"
1383
+ )
1370
1384
graph .process ()
1371
1385
1372
1386
self .assertEqual (
1373
1387
"Build on previous ideas: ${previous_responses}" ,
1374
1388
agent1 .combination_instructions ,
1375
1389
)
1376
1390
self .assertEqual (
1377
- DEFAULTS [' combination_instructions' ][ ' voting' ],
1391
+ DEFAULTS [" combination_instructions" ][ " voting" ],
1378
1392
agent2 .combination_instructions ,
1379
1393
)
1380
1394
self .assertEqual (
1381
- DEFAULTS [' combination_instructions' ][ ' voting' ],
1395
+ DEFAULTS [" combination_instructions" ][ " voting" ],
1382
1396
agent3 .combination_instructions ,
1383
1397
)
1384
1398
1399
+ self .assertIn ("single and" , agent2 .prompts [0 ]["user" ])
1400
+ self .assertIn ("single and" , agent3 .prompts [0 ]["user" ])
1401
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1402
+ self .assertNotIn ("${previous_responses}" , agent3 .prompts [0 ]["user" ])
1385
1403
self .assertEqual (3 , len (graph .responses ))
1386
1404
1387
1405
def test_no_individual_agent_combination_instructions (self ):
@@ -1394,21 +1412,32 @@ def test_no_individual_agent_combination_instructions(self):
1394
1412
agents = {"agent1" : agent1 , "agent2" : agent2 , "agent3" : agent3 }
1395
1413
edges = [("agent1" , "agent2" ), ("agent1" , "agent3" ), ("agent2" , "agent3" )]
1396
1414
1397
- graph = Graph (agents = agents , edges = edges , task = task , combination_instructions = "second_wave" )
1415
+ graph = Graph (
1416
+ agents = agents ,
1417
+ edges = edges ,
1418
+ task = task ,
1419
+ combination_instructions = "second_wave" ,
1420
+ )
1398
1421
graph .process ()
1399
1422
1400
1423
self .assertEqual (
1401
- DEFAULTS [' combination_instructions' ][ ' second_wave' ],
1424
+ DEFAULTS [" combination_instructions" ][ " second_wave" ],
1402
1425
agent1 .combination_instructions ,
1403
1426
)
1404
1427
self .assertEqual (
1405
- DEFAULTS [' combination_instructions' ][ ' second_wave' ],
1428
+ DEFAULTS [" combination_instructions" ][ " second_wave" ],
1406
1429
agent2 .combination_instructions ,
1407
1430
)
1408
1431
self .assertEqual (
1409
- DEFAULTS [' combination_instructions' ][ ' second_wave' ],
1432
+ DEFAULTS [" combination_instructions" ][ " second_wave" ],
1410
1433
agent3 .combination_instructions ,
1411
1434
)
1435
+
1436
+ self .assertIn ("Use empathy" , agent2 .prompts [0 ]["user" ])
1437
+ self .assertIn ("Use empathy" , agent3 .prompts [0 ]["user" ])
1438
+
1439
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1440
+ self .assertNotIn ("${previous_responses}" , agent3 .prompts [0 ]["user" ])
1412
1441
self .assertEqual (3 , len (graph .responses ))
1413
1442
1414
1443
def test_no_individual_agent_combination_instructions_default (self ):
@@ -1425,18 +1454,24 @@ def test_no_individual_agent_combination_instructions_default(self):
1425
1454
graph .process ()
1426
1455
1427
1456
self .assertEqual (
1428
- DEFAULTS [' combination_instructions' ][ ' default' ],
1457
+ DEFAULTS [" combination_instructions" ][ " default" ],
1429
1458
agent1 .combination_instructions ,
1430
1459
)
1431
1460
self .assertEqual (
1432
- DEFAULTS [' combination_instructions' ][ ' default' ],
1461
+ DEFAULTS [" combination_instructions" ][ " default" ],
1433
1462
agent2 .combination_instructions ,
1434
1463
)
1435
1464
self .assertEqual (
1436
- DEFAULTS [' combination_instructions' ][ ' default' ],
1465
+ DEFAULTS [" combination_instructions" ][ " default" ],
1437
1466
agent3 .combination_instructions ,
1438
1467
)
1439
1468
1469
+ self .assertIn ("USE PREVIOUS" , agent2 .prompts [0 ]["user" ])
1470
+ self .assertIn ("USE PREVIOUS" , agent3 .prompts [0 ]["user" ])
1471
+
1472
+ self .assertNotIn ("${previous_responses}" , agent2 .prompts [0 ]["user" ])
1473
+ self .assertNotIn ("${previous_responses}" , agent3 .prompts [0 ]["user" ])
1474
+
1440
1475
self .assertEqual (3 , len (graph .responses ))
1441
1476
1442
1477
def test_dict_to_list_conversion (self ):
0 commit comments