@@ -240,3 +240,74 @@ def claims():
240240 },
241241 },
242242 ]
243+
244+
245+ def test_bedrock_agent_with_empty_bedrock_response ():
246+ # GIVEN a Bedrock Agent event
247+ app = BedrockAgentResolver ()
248+
249+ @app .get ("/claims" , description = "Gets claims" )
250+ def claims ():
251+ return BedrockResponse (body = {"message" : "test" })
252+
253+ # WHEN calling the event handler
254+ result = app (load_event ("bedrockAgentEvent.json" ), {})
255+
256+ # THEN process event correctly without optional attributes
257+ assert result ["messageVersion" ] == "1.0"
258+ assert result ["response" ]["httpStatusCode" ] == 200
259+ assert "sessionAttributes" not in result
260+ assert "promptSessionAttributes" not in result
261+ assert "knowledgeBasesConfiguration" not in result
262+
263+
264+ def test_bedrock_agent_with_partial_bedrock_response ():
265+ # GIVEN a Bedrock Agent event
266+ app = BedrockAgentResolver ()
267+
268+ @app .get ("/claims" , description = "Gets claims" )
269+ def claims ():
270+ return BedrockResponse (
271+ body = {"message" : "test" },
272+ session_attributes = {"user_id" : "123" },
273+ # Only include session_attributes to test partial response
274+ )
275+
276+ # WHEN calling the event handler
277+ result = app (load_event ("bedrockAgentEvent.json" ), {})
278+
279+ # THEN process event correctly with only session_attributes
280+ assert result ["messageVersion" ] == "1.0"
281+ assert result ["response" ]["httpStatusCode" ] == 200
282+ assert result ["sessionAttributes" ] == {"user_id" : "123" }
283+ assert "promptSessionAttributes" not in result
284+ assert "knowledgeBasesConfiguration" not in result
285+
286+
287+ def test_bedrock_agent_with_different_attributes_combination ():
288+ # GIVEN a Bedrock Agent event
289+ app = BedrockAgentResolver ()
290+
291+ @app .get ("/claims" , description = "Gets claims" )
292+ def claims ():
293+ return BedrockResponse (
294+ body = {"message" : "test" },
295+ prompt_session_attributes = {"context" : "testing" },
296+ knowledge_bases_configuration = [
297+ {
298+ "knowledgeBaseId" : "kb-123" ,
299+ "retrievalConfiguration" : {"vectorSearchConfiguration" : {"numberOfResults" : 3 }},
300+ },
301+ ],
302+ # Omit session_attributes to test different combination
303+ )
304+
305+ # WHEN calling the event handler
306+ result = app (load_event ("bedrockAgentEvent.json" ), {})
307+
308+ # THEN process event correctly with specific attributes
309+ assert result ["messageVersion" ] == "1.0"
310+ assert result ["response" ]["httpStatusCode" ] == 200
311+ assert "sessionAttributes" not in result
312+ assert result ["promptSessionAttributes" ] == {"context" : "testing" }
313+ assert result ["knowledgeBasesConfiguration" ][0 ]["knowledgeBaseId" ] == "kb-123"
0 commit comments