input_text:str="I am looking to buy running shoes?"# replace this with a prompt relevant to your agentagent_id:str='#####'# note this from the agent console on Bedrockagent_alias_id:str='TSTALIASID'# fixed for draft version of the agentsession_id:str=str(uuid.uuid1())# random identifierenable_trace:bool=True
%%timeimportjsonevent_stream=response['completion']try:foreventinevent_stream:if'chunk'inevent:data=event['chunk']['bytes']logger.info(f"Final answer ->\n{data.decode('utf8')}")end_event_received=True# End event indicates that the request finished successfullyelif'trace'inevent:logger.info(json.dumps(event['trace'],indent=2))else:raiseException("unexpected event.",event)exceptExceptionase:raiseException("unexpected event.",e)