2222
2323
2424class BedrockResponse :
25+ """
26+ Contains the response body, status code, content type, and optional attributes
27+ for session management and knowledge base configuration.
28+ """
2529 def __init__ (
2630 self ,
2731 body : Any = None ,
@@ -38,9 +42,6 @@ def __init__(
3842 self .prompt_session_attributes = prompt_session_attributes
3943 self .knowledge_bases_configuration = knowledge_bases_configuration
4044
41- def is_json (self ) -> bool :
42- return self .content_type == "application/json"
43-
4445 def to_dict (self ) -> dict [str , Any ]:
4546 return {
4647 "body" : self .body ,
@@ -53,6 +54,11 @@ def to_dict(self) -> dict[str, Any]:
5354
5455
5556class BedrockResponseBuilder (ResponseBuilder ):
57+ """
58+ Bedrock Response Builder. This builds the response dict to be returned by Lambda when using Bedrock Agents.
59+
60+ Since the payload format is different from the standard API Gateway Proxy event, we override the build method.
61+ """
5662 @override
5763 def build (self , event : BedrockAgentEvent , * args ) -> dict [str , Any ]:
5864 self ._route (event , None )
@@ -89,7 +95,7 @@ def build(self, event: BedrockAgentEvent, *args) -> dict[str, Any]:
8995 if bedrock_response .prompt_session_attributes :
9096 response ["promptSessionAttributes" ] = bedrock_response .prompt_session_attributes
9197 if bedrock_response .knowledge_bases_configuration :
92- response ["knowledgeBasesConfiguration" ] = bedrock_response .knowledge_bases_configuration # type: ignore
98+ response ["knowledgeBasesConfiguration" ] = bedrock_response .knowledge_bases_configuration # type: ignore
9399
94100 return response
95101
0 commit comments