Using mobile agent systems, cooperative distributed applications that run over the Internet can be constructed flexibly. However, there are some problems: it is dificult to understand collaborations among agents and travels of individual agents as a whole because mobility/collaboration functions tend to be intertwined in the code; it is dificult to define behaviors of agents explicitly because they are influenced by their external context dynamically. Many aspects of mobility/collaboration strategies including traveling, coordination constraints, synchronization constraints and security-checking strategies should be considered when mobile agent applications are constructed. In this paper, the concept of RoleEP(Role Based Evolutionary Programming) is proposed in order to alleviate these problems. In RoleEP, a field where a group of agents roam around hosts and collaborate with each other is regarded as an environment and mobility/collaboration functions that an agent should assume in an environment are defined as roles. An object becomes an agent by binding itself to a role that is defined in an environment, and acquires mobility/collaboration functions dynamically. RoleEP provides a mechanism for separating concerns about mobility/collaboration into environments and a systematic evolutionary programming style. Distributed applications based on mobile agent systems, which may change their functions dynamically in order to adapt themselves to their external context, can be constructed by synthesizing environments dynamically.