Ambient intelligence (AmI) systems are now considered a promising approach to assist people in their daily life. AmI proposes the development of context aware systems equipped with devices that can recognize your context and act accordingly. Agents provide an effective way to develop such systems since agents are reactive, proactive and exhibit an intelligent and autonomous behavior. However, current agent approaches do not adequately fulfill the requirements posed by AmI systems. From a modeling point of view, the aim should be to help in the design by providing adequate tools that assist in the development of important properties of AmI systems, such as context-awareness; and from an implementation point of view, agent technologies must be adapted to the diversity of AmI devices and communication technologies. As a solution to these issues we propose a Model driven engineering process, which supports the automatic generation of agent-based AmI systems. The source metamodel is PIM4Agents, a general purpose agent metamodel that we have adapted to support the explicit modeling of context aware systems, and the target metamodel is Malaca, an aspect-oriented agent architecture. Aspect-orientation makes Malaca platform-neutral for FIPA compliant agent platforms, simplifying the model driven process. The solution generates MalacaTiny agents, an implementation of Malaca that is able to run in AmI devices. We have evaluated the convenience of applying a model driven approach by measuring the degree of automation of our process and we have evaluated MalacaTiny for mobile phones by assessing different parameters, related to the scarcity of resources in AmI systems. All the results obtained are satisfactory.