@@ -68,7 +68,7 @@ def invoke_agent(self, agent_id, agent_alias_id, session_id, prompt):
6868
6969 # snippet-end:[python.example_code.bedrock-agent-runtime.InvokeAgent]
7070
71- # snippet-start:[python.example_code.bedrock-agent-runtime.InvokeFlow]
71+ # snippet-start:[python.example_code.bedrock-agent-runtime.InvokeFlow]
7272 def invoke_flow (self , flow_id , flow_alias_id , input_data , execution_id ):
7373 """
7474 Invoke an Amazon Bedrock flow and handle the response stream.
@@ -81,10 +81,10 @@ def invoke_flow(self, flow_id, flow_alias_id, input_data, execution_id):
8181 execution_id: Execution ID for continuing a flow. Use the value None on first run.
8282
8383 Returns:
84- Dict containing flow_complete status, input_required info, and execution_id
84+ The response
8585 """
8686 try :
87- response = None
87+
8888 request_params = None
8989
9090 if execution_id is None :
@@ -109,37 +109,19 @@ def invoke_flow(self, flow_id, flow_alias_id, input_data, execution_id):
109109 if "executionId" not in request_params :
110110 execution_id = response ['executionId' ]
111111
112- input_required = None
113- flow_status = ""
112+ result = ""
114113
115- # Process the streaming response
114+ # Get the streaming response
116115 for event in response ['responseStream' ]:
116+ result = result + str (event ) + '\n '
117+ print (result )
117118
118- # Check if flow is complete.
119- if 'flowCompletionEvent' in event :
120- flow_status = event ['flowCompletionEvent' ]['completionReason' ]
121-
122- # Check if more input us needed from user.
123- elif 'flowMultiTurnInputRequestEvent' in event :
124- input_required = event
125-
126- # Print the model output.
127- elif 'flowOutputEvent' in event :
128- print (event ['flowOutputEvent' ]['content' ]['document' ])
129-
130- # Log trace events.
131- elif 'flowTraceEvent' in event :
132- logger .info ("Flow trace: %s" , event ['flowTraceEvent' ])
133-
134- return {
135- "flow_status" : flow_status ,
136- "input_required" : input_required ,
137- "execution_id" : execution_id
138- }
139119 except ClientError as e :
140120 logger .error ("Couldn't invoke flow %s." , {e })
141121 raise
142122
123+ return result
124+
143125 # snippet-end:[python.example_code.bedrock-agent-runtime.InvokeFlow]
144126
145127# snippet-end:[python.example_code.bedrock-agent-runtime.BedrockAgentsRuntimeWrapper.class]
0 commit comments