MCPcopy Create free account
hub / github.com/aws-samples/sample-devgenius-aws-solution-builder / read_agent_response

Function read_agent_response

chatbot/utils.py:128–149  ·  view source on GitHub ↗
(event_stream)

Source from the content-addressed store, hash-verified

126
127
128def read_agent_response(event_stream):
129 ask_user = False
130 agent_answer = ""
131 try:
132 for event in event_stream:
133 if 'chunk' in event:
134 data = event['chunk']['bytes']
135 agent_answer = data.decode('utf8')
136 elif 'trace' in event:
137 print(f"orchestration trace = {event['trace']['trace']['orchestrationTrace']}")
138 if 'observation' in event['trace']['trace']['orchestrationTrace']:
139 if event['trace']['trace']['orchestrationTrace']['observation']['type'] == "ASK_USER":
140 ask_user = True
141 else:
142 ask_user = False
143 else:
144 ask_user = False
145 else:
146 raise ValueError(f"Unexpected event: {event}")
147 except Exception as e:
148 raise ValueError(f"Unexpected Error:: {str(e)}")
149 return ask_user, agent_answer
150
151
152def prompts_to_messages(prompts):

Callers 2

reset_messagesFunction · 0.90
agent.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected