@@ -281,7 +281,6 @@ def strict_function(required_param):
281
281
282
282
# Function should raise a TypeError due to missing required parameter
283
283
assert "Error:" in result ["response" ]["functionResponse" ]["responseBody" ]["TEXT" ]["body" ]
284
- assert result ["response" ]["functionResponse" ]["responseState" ] == "FAILURE"
285
284
286
285
287
286
def test_bedrock_agent_function_with_complex_return_type ():
@@ -359,3 +358,67 @@ def test_resolve_with_no_current_event():
359
358
# THEN a ValueError should be raised
360
359
with pytest .raises (ValueError , match = "No event to process" ):
361
360
app ._resolve ()
361
+
362
+
363
+ def test_bedrock_agent_function_with_parameters_casting ():
364
+ # GIVEN a Bedrock Agent Function resolver
365
+ app = BedrockAgentFunctionResolver ()
366
+
367
+ @app .tool (description = "Function that accepts parameters" )
368
+ def vacation_request (month : int , payment : float , approved : bool ):
369
+ # Store received parameters for assertion
370
+ assert isinstance (month , int )
371
+ assert isinstance (payment , float )
372
+ assert isinstance (approved , bool )
373
+ return "Vacation request"
374
+
375
+ # WHEN calling the event handler with parameters
376
+ raw_event = load_event ("bedrockAgentFunctionEvent.json" )
377
+ raw_event ["function" ] = "vacation_request"
378
+ raw_event ["parameters" ] = [
379
+ {"name" : "month" , "value" : "3" , "type" : "integer" },
380
+ {"name" : "payment" , "value" : "1000.5" , "type" : "number" },
381
+ {"name" : "approved" , "value" : False , "type" : "boolean" },
382
+ ]
383
+ result = app .resolve (raw_event , {})
384
+
385
+ # THEN parameters should be correctly passed to the function
386
+ assert "Vacation request" == result ["response" ]["functionResponse" ]["responseBody" ]["TEXT" ]["body" ]
387
+
388
+
389
+ def test_bedrock_agent_function_with_parameters_casting_errors ():
390
+ # GIVEN a Bedrock Agent Function resolver
391
+ app = BedrockAgentFunctionResolver ()
392
+
393
+ @app .tool (description = "Function that handles parameter casting errors" )
394
+ def process_data (id_product : str , quantity : int , price : float , available : bool , items : list ):
395
+ # Check that invalid values maintain their original types
396
+ assert isinstance (id_product , str )
397
+ # For invalid integer, the original string should be preserved
398
+ assert quantity == "invalid_number"
399
+ # For invalid float, the original string should be preserved
400
+ assert price == "not_a_price"
401
+ # For invalid boolean, should evaluate based on Python's bool rules
402
+ assert isinstance (available , bool )
403
+ assert not available
404
+ # Arrays should remain as is
405
+ assert isinstance (items , list )
406
+ return "Processed with casting errors handled"
407
+
408
+ # WHEN calling the event handler with parameters that cause casting errors
409
+ raw_event = load_event ("bedrockAgentFunctionEvent.json" )
410
+ raw_event ["function" ] = "process_data"
411
+ raw_event ["parameters" ] = [
412
+ {"name" : "id_product" , "value" : 12345 , "type" : "string" }, # Integer to string (should work)
413
+ {"name" : "quantity" , "value" : "invalid_number" , "type" : "integer" }, # Will cause ValueError
414
+ {"name" : "price" , "value" : "not_a_price" , "type" : "number" }, # Will cause ValueError
415
+ {"name" : "available" , "value" : "invalid_bool" , "type" : "boolean" }, # Not "true"/"false"
416
+ {"name" : "items" , "value" : ["item1" , "item2" ], "type" : "array" }, # Array should remain as is
417
+ ]
418
+ result = app .resolve (raw_event , {})
419
+
420
+ # THEN parameters should be handled properly despite casting errors
421
+ assert (
422
+ "Processed with casting errors handled"
423
+ == result ["response" ]["functionResponse" ]["responseBody" ]["TEXT" ]["body" ]
424
+ )
0 commit comments