@ -711,20 +711,25 @@ class Agent:
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                while  attempt  <  self . retry_attempts  and  not  success : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                    try : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        if  self . long_term_memory  is  not  None : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            logger . info ( 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                " Querying long term memory... " 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            logger . info ( " Querying long term memory... " ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            self . memory_query ( task_prompt ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        # Generate response using LLM 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        response  =  self . llm ( task_prompt ,  * args ,  * * kwargs ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        # Check if response is a dictionary and has 'choices' key 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        if  isinstance ( response ,  dict )  and  ' choices '  in  response : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            response  =  response [ ' choices ' ] [ 0 ] [ ' message ' ] [ ' content ' ] 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        elif  isinstance ( response ,  str ) : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            # If response is already a string, use it as is 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            pass 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        else : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            response_args  =  ( 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                ( task_prompt ,  * args ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                if  img  is  None 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                else  ( task_prompt ,  img ,  * args ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            response  =  self . call_llm ( 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                * response_args ,  * * kwargs 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            raise  ValueError ( f " Unexpected response format:  { type ( response ) } " ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        # Check and execute tools 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        if  self . tools  is  not  None : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            print ( f " self.tools is not None:  { response } " ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            self . parse_and_execute_tools ( response ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        # Log the step metadata 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        logged  =  self . log_step_metadata ( 
 
				
			 
			
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
				 
				 
				
					@ -806,8 +811,7 @@ class Agent:
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                    except  Exception  as  e : 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        logger . error ( 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            f " Attempt  { attempt + 1 } : Error generating " 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            f "  response:  { e } " 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                            f " Attempt  { attempt + 1 } : Error generating response:  { e } " 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        ) 
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                        attempt  + =  1