@@ -458,7 +458,7 @@ def test_moderator_manual(self):
458
458
mod = Moderator (
459
459
persona = "You are a conservative moderator overseeing a discussion about the following task: ${task}." ,
460
460
combination_instructions = "- Here are the previous responses: ${previous_responses}- Take only the most "
461
- "conservative parts of what was previously said." ,
461
+ "conservative parts of what was previously said." ,
462
462
)
463
463
mixed = Chain ([a2 , a3 , a4 ], task = self .task , moderator = mod )
464
464
mixed .process ()
@@ -525,16 +525,16 @@ def test_chain_multiple_cycles(self):
525
525
chain = Chain ([agent1 , agent2 ], task = task , cycles = 3 )
526
526
527
527
with patch .object (
528
- Agent ,
529
- "_get_response" ,
530
- side_effect = [
531
- "Pros: flexibility, no commute. Cons: isolation." ,
532
- "Pros: reduced office costs. Cons: difficulty in team building." ,
533
- "Agree on flexibility, add increased productivity as pro." ,
534
- "Agree on team building issues, add potential for overwork." ,
535
- "Emphasize need for balance and hybrid models." ,
536
- "Suggest importance of clear communication and expectations." ,
537
- ],
528
+ Agent ,
529
+ "_get_response" ,
530
+ side_effect = [
531
+ "Pros: flexibility, no commute. Cons: isolation." ,
532
+ "Pros: reduced office costs. Cons: difficulty in team building." ,
533
+ "Agree on flexibility, add increased productivity as pro." ,
534
+ "Agree on team building issues, add potential for overwork." ,
535
+ "Emphasize need for balance and hybrid models." ,
536
+ "Suggest importance of clear communication and expectations." ,
537
+ ],
538
538
):
539
539
chain .process ()
540
540
@@ -745,9 +745,9 @@ def test_chain_current_task_description(self):
745
745
746
746
# Mock ONLY _get_response from `process()`.
747
747
with patch .object (
748
- Agent ,
749
- "_get_response" ,
750
- return_value = "Social media has both positive and negative impacts on society." ,
748
+ Agent ,
749
+ "_get_response" ,
750
+ return_value = "Social media has both positive and negative impacts on society." ,
751
751
):
752
752
chain .process ()
753
753
@@ -786,13 +786,13 @@ def test_chain_with_different_agent_tasks(self):
786
786
chain = Chain ([agent1 , agent2 , agent3 ])
787
787
788
788
with patch .object (
789
- Agent ,
790
- "_get_response" ,
791
- side_effect = [
792
- "Pros: flexibility, no commute." ,
793
- "Cons: isolation, difficulty in team building." ,
794
- "Summary: Remote work offers flexibility but poses challenges in collaboration." ,
795
- ],
789
+ Agent ,
790
+ "_get_response" ,
791
+ side_effect = [
792
+ "Pros: flexibility, no commute." ,
793
+ "Cons: isolation, difficulty in team building." ,
794
+ "Summary: Remote work offers flexibility but poses challenges in collaboration." ,
795
+ ],
796
796
):
797
797
chain .process ()
798
798
@@ -974,14 +974,14 @@ def test_debate_with_different_agent_tasks(self):
974
974
debate = Debate ([agent1 , agent2 ], cycles = 2 )
975
975
976
976
with patch .object (
977
- Agent ,
978
- "_get_response" ,
979
- side_effect = [
980
- "Stricter laws will reduce gun violence." ,
981
- "Stricter laws infringe on Second Amendment rights." ,
982
- "Gun control laws have been effective in other countries." ,
983
- "Law-abiding citizens need guns for self-defense." ,
984
- ],
977
+ Agent ,
978
+ "_get_response" ,
979
+ side_effect = [
980
+ "Stricter laws will reduce gun violence." ,
981
+ "Stricter laws infringe on Second Amendment rights." ,
982
+ "Gun control laws have been effective in other countries." ,
983
+ "Law-abiding citizens need guns for self-defense." ,
984
+ ],
985
985
):
986
986
debate .process ()
987
987
@@ -1251,13 +1251,13 @@ def test_graph_with_different_agent_tasks(self):
1251
1251
graph = Graph (agents = agents , edges = edges )
1252
1252
1253
1253
with patch .object (
1254
- Agent ,
1255
- "process" ,
1256
- side_effect = [
1257
- "Economic policies should focus on growth." ,
1258
- "Social policies should address inequality." ,
1259
- "Both economic growth and social equality are important policy goals." ,
1260
- ],
1254
+ Agent ,
1255
+ "process" ,
1256
+ side_effect = [
1257
+ "Economic policies should focus on growth." ,
1258
+ "Social policies should address inequality." ,
1259
+ "Both economic growth and social equality are important policy goals." ,
1260
+ ],
1261
1261
):
1262
1262
final_response = graph .process ()
1263
1263
@@ -2087,11 +2087,12 @@ def test_structure_repr_with_empty_collections(self):
2087
2087
print (repr_string )
2088
2088
self .assertIn ("'responses': []" , repr_string )
2089
2089
2090
+
2090
2091
class TestPathHandling (unittest .TestCase ):
2091
2092
"""Test cases for resource path handling."""
2092
2093
2093
2094
def test_load_yaml_pkg_resources_paths (self ):
2094
- """Test load_yaml works both with and without pkg_resources."""
2095
+ """Test load_yaml works both with and without pkg_resources. This has to do with different versions of Python """
2095
2096
2096
2097
# test we can load stuff with pkg_resources
2097
2098
yaml_content_pkg_resources = load_yaml ("instructions.yaml" )
@@ -2106,9 +2107,131 @@ def test_load_yaml_pkg_resources_paths(self):
2106
2107
self .assertIn ("persona_template" , yaml_content_pathlib )
2107
2108
self .assertIn ("combination_instructions" , yaml_content_pathlib )
2108
2109
2109
- # assert equality of the two methods
2110
2110
self .assertEqual (yaml_content_pkg_resources , yaml_content_pathlib )
2111
2111
2112
2112
2113
+ class CombinationInstructionExpansionTests (unittest .TestCase ):
2114
+ """Tests verifying the proper expansion of combination instruction templates across structures
2115
+
2116
+ Notes:
2117
+ - We don't need to test ensemble because it never uses combination instructions
2118
+ - The reason why I am redefining agents a bunch of times is because if you use the same Agents, e.g. in setup,
2119
+ then their combination instructions are already set
2120
+
2121
+ """
2122
+
2123
+ def test_structure_template_expansion (self ):
2124
+ """Test that when no agent has combination instructions, they inherit correctly expanded template from structure"""
2125
+ task = "Generate argument for social media in 10 words."
2126
+
2127
+ # Chain
2128
+ chain_agents = [
2129
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2130
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2131
+ ]
2132
+ chain = Chain (chain_agents , task = task , combination_instructions = "chain" )
2133
+ chain .process ()
2134
+ chain_template = DEFAULTS ["combination_instructions" ]["chain" ]
2135
+ for agent in chain .agents :
2136
+ self .assertEqual (chain_template , agent .combination_instructions )
2137
+
2138
+ debate_agents = [
2139
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2140
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2141
+ ]
2142
+ debate = Debate (debate_agents , task = task , combination_instructions = "debate" )
2143
+ debate .process ()
2144
+ debate_template = DEFAULTS ["combination_instructions" ]["debate" ]
2145
+ for agent in debate .agents :
2146
+ self .assertEqual (debate_template , agent .combination_instructions )
2147
+
2148
+ graph_agents = {
2149
+ "agent1" : Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2150
+ "agent2" : Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2151
+ }
2152
+ graph = Graph (
2153
+ agents = graph_agents ,
2154
+ edges = [("agent1" , "agent2" )],
2155
+ combination_instructions = "critique_revise"
2156
+ )
2157
+ graph .process ()
2158
+ critique_template = DEFAULTS ["combination_instructions" ]["critique_revise" ]
2159
+ for agent in graph .agents :
2160
+ self .assertEqual (critique_template , agent .combination_instructions )
2161
+
2162
+ def test_agent_template_expansion (self ):
2163
+ """Test that agents with template names get their templates properly expanded"""
2164
+ task = "Generate argument for social media in 10 words."
2165
+
2166
+ chain_agents = [
2167
+ Agent (task = task , combination_instructions = "default" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2168
+ Agent (task = task , combination_instructions = "chain" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2169
+ ]
2170
+ chain = Chain (chain_agents , task = task )
2171
+ chain .process ()
2172
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["default" ], chain_agents [0 ].combination_instructions )
2173
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["chain" ], chain_agents [1 ].combination_instructions )
2174
+
2175
+ debate_agents = [
2176
+ Agent (task = task , combination_instructions = "debate" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2177
+ Agent (task = task , combination_instructions = "default" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2178
+ ]
2179
+ debate = Debate (debate_agents , task = task )
2180
+ debate .process ()
2181
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["debate" ], debate_agents [0 ].combination_instructions )
2182
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["default" ], debate_agents [1 ].combination_instructions )
2183
+
2184
+ graph_agents = {
2185
+ "agent1" : Agent (task = task , combination_instructions = "critique_revise" , model = "gpt-3.5-turbo" ,
2186
+ kwargs = {"max_tokens" : 30 }),
2187
+ "agent2" : Agent (task = task , combination_instructions = "default" , model = "gpt-3.5-turbo" ,
2188
+ kwargs = {"max_tokens" : 30 })
2189
+ }
2190
+ graph = Graph (agents = graph_agents , edges = [("agent1" , "agent2" )])
2191
+ graph .process ()
2192
+ agent_list = list (graph_agents .values ())
2193
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["critique_revise" ],
2194
+ agent_list [0 ].combination_instructions )
2195
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["default" ], agent_list [1 ].combination_instructions )
2196
+
2197
+ def test_mixed_template_expansion (self ):
2198
+ """Test when some agents have templates and others don't"""
2199
+ task = "Generate argument for social media in 10 words."
2200
+
2201
+ chain_agents = [
2202
+ Agent (task = task , combination_instructions = "default" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2203
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2204
+ ]
2205
+ chain = Chain (chain_agents , task = task , combination_instructions = "chain" )
2206
+ chain .process ()
2207
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["default" ], chain_agents [0 ].combination_instructions )
2208
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["chain" ], chain_agents [1 ].combination_instructions )
2209
+
2210
+ debate_agents = [
2211
+ Agent (task = task , combination_instructions = "debate" , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 }),
2212
+ Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2213
+ ]
2214
+ debate = Debate (debate_agents , task = task , combination_instructions = "chain" )
2215
+ debate .process ()
2216
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["debate" ], debate_agents [0 ].combination_instructions )
2217
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["chain" ], debate_agents [1 ].combination_instructions )
2218
+
2219
+ graph_agents = {
2220
+ "agent1" : Agent (task = task , combination_instructions = "critique_revise" , model = "gpt-3.5-turbo" ,
2221
+ kwargs = {"max_tokens" : 30 }),
2222
+ "agent2" : Agent (task = task , model = "gpt-3.5-turbo" , kwargs = {"max_tokens" : 30 })
2223
+ }
2224
+ graph = Graph (
2225
+ agents = graph_agents ,
2226
+ edges = [("agent1" , "agent2" )],
2227
+ combination_instructions = "chain"
2228
+ )
2229
+ graph .process ()
2230
+ agent_list = list (graph_agents .values ())
2231
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["critique_revise" ],
2232
+ agent_list [0 ].combination_instructions )
2233
+ self .assertEqual (DEFAULTS ["combination_instructions" ]["chain" ], agent_list [1 ].combination_instructions )
2234
+
2235
+
2113
2236
if __name__ == "__main__" :
2114
2237
unittest .main ()
0 commit comments