The first generation of IoT was developed and deployed all over the world by connecting devices with common functionalities that were not sufficiently efficient or reliable for use in dynamic situations that require adaptive solutions. However, these fundamental IoT functions and services mainly targeted stable environments; there is consequently a strong need for the next generation of IoT services to be smarter, faster, and more reliable. We believe that the hyper-connected IoT ecosystem on fog platforms with contextual AI technologies is a promising solution. In this work, we introduce the EiF, a flexible fog computing framework that runs on IoT gateways with adaptive AI services fostered on the cloud. Our approach can be viewed as an integration of three emerging technologies, namely IoT, fog, and AI. Generally, EiF virtualizes an IoT service layer platform for fog nodes, and provides functions to manage and orchestrate various fog nodes; upon service virtualization and orchestration, AI services are fostered within both the federated cloud and distributed edge side and are deployed on fog nodes. We demonstrate the feasibility of EiF via the example of intelligent traffic flow monitoring and management.