@@ -36,9 +36,6 @@ def test_load_agent_with_simple_structured_output_reference(self, mock_agent_cla
3636 mock_agent_class .return_value = mock_agent
3737
3838 config = {
39- "name" : "test_agent" ,
40- "model" : "test_model" ,
41- "system_prompt" : "Test prompt" ,
4239 "schemas" : [
4340 {
4441 "name" : "UserProfile" ,
@@ -49,7 +46,12 @@ def test_load_agent_with_simple_structured_output_reference(self, mock_agent_cla
4946 },
5047 }
5148 ],
52- "structured_output" : "UserProfile" ,
49+ "agent" : {
50+ "name" : "test_agent" ,
51+ "model" : "test_model" ,
52+ "system_prompt" : "Test prompt" ,
53+ "structured_output" : "UserProfile" ,
54+ },
5355 }
5456
5557 agent = self .loader .load_agent (config )
@@ -71,13 +73,15 @@ def test_load_agent_with_python_class_reference(self, mock_agent_class):
7173 mock_agent_class .return_value = mock_agent
7274
7375 config = {
74- "name" : "test_agent" ,
75- "model" : "test_model" ,
76- "system_prompt" : "Test prompt" ,
77- "structured_output" : (
78- "tests.strands.experimental.config_loader.agent."
79- "test_agent_config_loader_structured_output.BusinessModel"
80- ),
76+ "agent" : {
77+ "name" : "test_agent" ,
78+ "model" : "test_model" ,
79+ "system_prompt" : "Test prompt" ,
80+ "structured_output" : (
81+ "tests.strands.experimental.config_loader.agent."
82+ "test_agent_config_loader_structured_output.BusinessModel"
83+ ),
84+ }
8185 }
8286
8387 self .loader .load_agent (config )
@@ -94,9 +98,6 @@ def test_load_agent_with_detailed_structured_output_config(self, mock_agent_clas
9498 mock_agent_class .return_value = mock_agent
9599
96100 config = {
97- "name" : "test_agent" ,
98- "model" : "test_model" ,
99- "system_prompt" : "Test prompt" ,
100101 "schemas" : [
101102 {
102103 "name" : "CustomerData" ,
@@ -107,10 +108,19 @@ def test_load_agent_with_detailed_structured_output_config(self, mock_agent_clas
107108 },
108109 }
109110 ],
110- "structured_output" : {
111- "schema" : "CustomerData" ,
112- "validation" : {"strict" : True , "allow_extra_fields" : False },
113- "error_handling" : {"retry_on_validation_error" : True , "max_retries" : 3 },
111+ "structured_output_defaults" : {
112+ "validation" : {"strict" : False , "allow_extra_fields" : True },
113+ "error_handling" : {"retry_on_validation_error" : False , "max_retries" : 1 },
114+ },
115+ "agent" : {
116+ "name" : "test_agent" ,
117+ "model" : "test_model" ,
118+ "system_prompt" : "Test prompt" ,
119+ "structured_output" : {
120+ "schema" : "CustomerData" ,
121+ "validation" : {"strict" : True , "allow_extra_fields" : False },
122+ "error_handling" : {"retry_on_validation_error" : True , "max_retries" : 3 },
123+ },
114124 },
115125 }
116126
@@ -148,11 +158,13 @@ def test_load_agent_with_external_schema_file(self, mock_agent_class):
148158
149159 try :
150160 config = {
151- "name" : "test_agent" ,
152- "model" : "test_model" ,
153- "system_prompt" : "Test prompt" ,
154161 "schemas" : [{"name" : "Product" , "schema_file" : temp_file }],
155- "structured_output" : "Product" ,
162+ "agent" : {
163+ "name" : "test_agent" ,
164+ "model" : "test_model" ,
165+ "system_prompt" : "Test prompt" ,
166+ "structured_output" : "Product" ,
167+ },
156168 }
157169
158170 self .loader .load_agent (config )
@@ -172,9 +184,6 @@ def test_load_agent_with_structured_output_defaults(self, mock_agent_class):
172184 mock_agent_class .return_value = mock_agent
173185
174186 config = {
175- "name" : "test_agent" ,
176- "model" : "test_model" ,
177- "system_prompt" : "Test prompt" ,
178187 "schemas" : [
179188 {
180189 "name" : "TestSchema" ,
@@ -185,10 +194,15 @@ def test_load_agent_with_structured_output_defaults(self, mock_agent_class):
185194 "validation" : {"strict" : False , "allow_extra_fields" : True },
186195 "error_handling" : {"retry_on_validation_error" : False , "max_retries" : 1 },
187196 },
188- "structured_output" : {
189- "schema" : "TestSchema" ,
190- "validation" : {
191- "strict" : True # Should override default
197+ "agent" : {
198+ "name" : "test_agent" ,
199+ "model" : "test_model" ,
200+ "system_prompt" : "Test prompt" ,
201+ "structured_output" : {
202+ "schema" : "TestSchema" ,
203+ "validation" : {
204+ "strict" : True # Should override default
205+ },
192206 },
193207 },
194208 }
@@ -214,18 +228,22 @@ def test_load_multiple_agents_with_shared_schemas(self, mock_agent_class):
214228 mock_agent_class .side_effect = [mock_agent1 , mock_agent2 ]
215229
216230 # Configuration with shared schemas
217- base_config = {
218- "schemas" : [
219- {
220- "name" : "SharedSchema" ,
221- "schema" : {"type" : "object" , "properties" : {"data" : {"type" : "string" }}, "required" : ["data" ]},
222- }
223- ]
224- }
231+ base_schemas = [
232+ {
233+ "name" : "SharedSchema" ,
234+ "schema" : {"type" : "object" , "properties" : {"data" : {"type" : "string" }}, "required" : ["data" ]},
235+ }
236+ ]
225237
226- agent1_config = {** base_config , "name" : "agent1" , "model" : "test_model" , "structured_output" : "SharedSchema" }
238+ agent1_config = {
239+ "schemas" : base_schemas ,
240+ "agent" : {"name" : "agent1" , "model" : "test_model" , "structured_output" : "SharedSchema" },
241+ }
227242
228- agent2_config = {** base_config , "name" : "agent2" , "model" : "test_model" , "structured_output" : "SharedSchema" }
243+ agent2_config = {
244+ "schemas" : base_schemas ,
245+ "agent" : {"name" : "agent2" , "model" : "test_model" , "structured_output" : "SharedSchema" },
246+ }
229247
230248 # Load first agent (should load schemas)
231249 self .loader .load_agent (agent1_config )
@@ -264,7 +282,7 @@ def test_error_handling_invalid_schema_reference(self, mock_agent_class):
264282 mock_agent .name = "test_agent"
265283 mock_agent_class .return_value = mock_agent
266284
267- config = {"name" : "test_agent" , "model" : "test_model" , "structured_output" : "NonExistentSchema" }
285+ config = {"agent" : { " name" : "test_agent" , "model" : "test_model" , "structured_output" : "NonExistentSchema" } }
268286
269287 with pytest .raises (ValueError , match = "Schema 'NonExistentSchema' not found" ):
270288 self .loader .load_agent (config )
@@ -276,7 +294,9 @@ def test_error_handling_invalid_python_class(self, mock_agent_class):
276294 mock_agent .name = "test_agent"
277295 mock_agent_class .return_value = mock_agent
278296
279- config = {"name" : "test_agent" , "model" : "test_model" , "structured_output" : "non.existent.module.Class" }
297+ config = {
298+ "agent" : {"name" : "test_agent" , "model" : "test_model" , "structured_output" : "non.existent.module.Class" }
299+ }
280300
281301 with pytest .raises (ValueError , match = "Cannot import Pydantic class" ):
282302 self .loader .load_agent (config )
@@ -289,12 +309,14 @@ def test_error_handling_missing_schema_in_detailed_config(self, mock_agent_class
289309 mock_agent_class .return_value = mock_agent
290310
291311 config = {
292- "name" : "test_agent" ,
293- "model" : "test_model" ,
294- "structured_output" : {
295- "validation" : {"strict" : True }
296- # Missing "schema" field
297- },
312+ "agent" : {
313+ "name" : "test_agent" ,
314+ "model" : "test_model" ,
315+ "structured_output" : {
316+ "validation" : {"strict" : True }
317+ # Missing "schema" field
318+ },
319+ }
298320 }
299321
300322 with pytest .raises (ValueError , match = "Structured output configuration must specify 'schema'" ):
@@ -308,9 +330,11 @@ def test_error_handling_invalid_structured_output_type(self, mock_agent_class):
308330 mock_agent_class .return_value = mock_agent
309331
310332 config = {
311- "name" : "test_agent" ,
312- "model" : "test_model" ,
313- "structured_output" : 123 , # Invalid type
333+ "agent" : {
334+ "name" : "test_agent" ,
335+ "model" : "test_model" ,
336+ "structured_output" : 123 , # Invalid type
337+ }
314338 }
315339
316340 with pytest .raises (ValueError , match = "structured_output must be a string reference or configuration dict" ):
@@ -331,15 +355,17 @@ def test_structured_output_method_replacement(self, mock_agent_class):
331355 mock_agent_class .return_value = mock_agent
332356
333357 config = {
334- "name" : "test_agent" ,
335- "model" : "test_model" ,
336358 "schemas" : [
337359 {
338360 "name" : "TestSchema" ,
339361 "schema" : {"type" : "object" , "properties" : {"name" : {"type" : "string" }}, "required" : ["name" ]},
340362 }
341363 ],
342- "structured_output" : "TestSchema" ,
364+ "agent" : {
365+ "name" : "test_agent" ,
366+ "model" : "test_model" ,
367+ "structured_output" : "TestSchema" ,
368+ },
343369 }
344370
345371 agent = self .loader .load_agent (config )
@@ -368,15 +394,17 @@ def test_convenience_method_creation(self, mock_agent_class):
368394 mock_agent_class .return_value = mock_agent
369395
370396 config = {
371- "name" : "test_agent" ,
372- "model" : "test_model" ,
373397 "schemas" : [
374398 {
375399 "name" : "CustomerProfile" ,
376400 "schema" : {"type" : "object" , "properties" : {"name" : {"type" : "string" }}, "required" : ["name" ]},
377401 }
378402 ],
379- "structured_output" : "CustomerProfile" ,
403+ "agent" : {
404+ "name" : "test_agent" ,
405+ "model" : "test_model" ,
406+ "structured_output" : "CustomerProfile" ,
407+ },
380408 }
381409
382410 self .loader .load_agent (config )
@@ -393,8 +421,10 @@ def test_global_schemas_loaded_once(self):
393421 "schema" : {"type" : "object" , "properties" : {"data" : {"type" : "string" }}, "required" : ["data" ]},
394422 }
395423 ],
396- "name" : "test_agent" ,
397- "model" : "test_model" ,
424+ "agent" : {
425+ "name" : "test_agent" ,
426+ "model" : "test_model" ,
427+ },
398428 }
399429
400430 # Mock the _load_global_schemas method to track calls
0 commit comments