@@ -36,9 +36,6 @@ def test_load_agent_with_simple_structured_output_reference(self, mock_agent_cla
36
36
mock_agent_class .return_value = mock_agent
37
37
38
38
config = {
39
- "name" : "test_agent" ,
40
- "model" : "test_model" ,
41
- "system_prompt" : "Test prompt" ,
42
39
"schemas" : [
43
40
{
44
41
"name" : "UserProfile" ,
@@ -49,7 +46,12 @@ def test_load_agent_with_simple_structured_output_reference(self, mock_agent_cla
49
46
},
50
47
}
51
48
],
52
- "structured_output" : "UserProfile" ,
49
+ "agent" : {
50
+ "name" : "test_agent" ,
51
+ "model" : "test_model" ,
52
+ "system_prompt" : "Test prompt" ,
53
+ "structured_output" : "UserProfile" ,
54
+ },
53
55
}
54
56
55
57
agent = self .loader .load_agent (config )
@@ -71,13 +73,15 @@ def test_load_agent_with_python_class_reference(self, mock_agent_class):
71
73
mock_agent_class .return_value = mock_agent
72
74
73
75
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
+ }
81
85
}
82
86
83
87
self .loader .load_agent (config )
@@ -94,9 +98,6 @@ def test_load_agent_with_detailed_structured_output_config(self, mock_agent_clas
94
98
mock_agent_class .return_value = mock_agent
95
99
96
100
config = {
97
- "name" : "test_agent" ,
98
- "model" : "test_model" ,
99
- "system_prompt" : "Test prompt" ,
100
101
"schemas" : [
101
102
{
102
103
"name" : "CustomerData" ,
@@ -107,10 +108,19 @@ def test_load_agent_with_detailed_structured_output_config(self, mock_agent_clas
107
108
},
108
109
}
109
110
],
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
+ },
114
124
},
115
125
}
116
126
@@ -148,11 +158,13 @@ def test_load_agent_with_external_schema_file(self, mock_agent_class):
148
158
149
159
try :
150
160
config = {
151
- "name" : "test_agent" ,
152
- "model" : "test_model" ,
153
- "system_prompt" : "Test prompt" ,
154
161
"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
+ },
156
168
}
157
169
158
170
self .loader .load_agent (config )
@@ -172,9 +184,6 @@ def test_load_agent_with_structured_output_defaults(self, mock_agent_class):
172
184
mock_agent_class .return_value = mock_agent
173
185
174
186
config = {
175
- "name" : "test_agent" ,
176
- "model" : "test_model" ,
177
- "system_prompt" : "Test prompt" ,
178
187
"schemas" : [
179
188
{
180
189
"name" : "TestSchema" ,
@@ -185,10 +194,15 @@ def test_load_agent_with_structured_output_defaults(self, mock_agent_class):
185
194
"validation" : {"strict" : False , "allow_extra_fields" : True },
186
195
"error_handling" : {"retry_on_validation_error" : False , "max_retries" : 1 },
187
196
},
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
+ },
192
206
},
193
207
},
194
208
}
@@ -214,18 +228,22 @@ def test_load_multiple_agents_with_shared_schemas(self, mock_agent_class):
214
228
mock_agent_class .side_effect = [mock_agent1 , mock_agent2 ]
215
229
216
230
# 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
+ ]
225
237
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
+ }
227
242
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
+ }
229
247
230
248
# Load first agent (should load schemas)
231
249
self .loader .load_agent (agent1_config )
@@ -264,7 +282,7 @@ def test_error_handling_invalid_schema_reference(self, mock_agent_class):
264
282
mock_agent .name = "test_agent"
265
283
mock_agent_class .return_value = mock_agent
266
284
267
- config = {"name" : "test_agent" , "model" : "test_model" , "structured_output" : "NonExistentSchema" }
285
+ config = {"agent" : { " name" : "test_agent" , "model" : "test_model" , "structured_output" : "NonExistentSchema" } }
268
286
269
287
with pytest .raises (ValueError , match = "Schema 'NonExistentSchema' not found" ):
270
288
self .loader .load_agent (config )
@@ -276,7 +294,9 @@ def test_error_handling_invalid_python_class(self, mock_agent_class):
276
294
mock_agent .name = "test_agent"
277
295
mock_agent_class .return_value = mock_agent
278
296
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
+ }
280
300
281
301
with pytest .raises (ValueError , match = "Cannot import Pydantic class" ):
282
302
self .loader .load_agent (config )
@@ -289,12 +309,14 @@ def test_error_handling_missing_schema_in_detailed_config(self, mock_agent_class
289
309
mock_agent_class .return_value = mock_agent
290
310
291
311
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
+ }
298
320
}
299
321
300
322
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):
308
330
mock_agent_class .return_value = mock_agent
309
331
310
332
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
+ }
314
338
}
315
339
316
340
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):
331
355
mock_agent_class .return_value = mock_agent
332
356
333
357
config = {
334
- "name" : "test_agent" ,
335
- "model" : "test_model" ,
336
358
"schemas" : [
337
359
{
338
360
"name" : "TestSchema" ,
339
361
"schema" : {"type" : "object" , "properties" : {"name" : {"type" : "string" }}, "required" : ["name" ]},
340
362
}
341
363
],
342
- "structured_output" : "TestSchema" ,
364
+ "agent" : {
365
+ "name" : "test_agent" ,
366
+ "model" : "test_model" ,
367
+ "structured_output" : "TestSchema" ,
368
+ },
343
369
}
344
370
345
371
agent = self .loader .load_agent (config )
@@ -368,15 +394,17 @@ def test_convenience_method_creation(self, mock_agent_class):
368
394
mock_agent_class .return_value = mock_agent
369
395
370
396
config = {
371
- "name" : "test_agent" ,
372
- "model" : "test_model" ,
373
397
"schemas" : [
374
398
{
375
399
"name" : "CustomerProfile" ,
376
400
"schema" : {"type" : "object" , "properties" : {"name" : {"type" : "string" }}, "required" : ["name" ]},
377
401
}
378
402
],
379
- "structured_output" : "CustomerProfile" ,
403
+ "agent" : {
404
+ "name" : "test_agent" ,
405
+ "model" : "test_model" ,
406
+ "structured_output" : "CustomerProfile" ,
407
+ },
380
408
}
381
409
382
410
self .loader .load_agent (config )
@@ -393,8 +421,10 @@ def test_global_schemas_loaded_once(self):
393
421
"schema" : {"type" : "object" , "properties" : {"data" : {"type" : "string" }}, "required" : ["data" ]},
394
422
}
395
423
],
396
- "name" : "test_agent" ,
397
- "model" : "test_model" ,
424
+ "agent" : {
425
+ "name" : "test_agent" ,
426
+ "model" : "test_model" ,
427
+ },
398
428
}
399
429
400
430
# Mock the _load_global_schemas method to track calls
0 commit comments