Learning from biological mechanisms is an essential method of devising interaction rules among agents. Inspired by neuropsychology, we introduce empathy, a vital ability of higher animals' affective systems, to assist us in analyzing and designing multi-agent systems. In this paper, we abstract the process of empathy as an optimization problem and establish a reasonable model of empathy by optimizing the corresponding free energy. Variable temperatures on the integrated utility associated with empathy provide agents with several different modes, including collectivity, equality, oligopoly, and monopoly. Therefore, we can change the agent's mode artificially according to the task requirement and examine agents' evolution from the perspective of continuous changes on temperature. Then we present a bandit algorithm called Empathy-based Interactive Learner (EIL), by which agents can enable affective utility evaluation and adaptive learning procedure in multi-agent systems. We test EIL's performance in four games, including the iterated prisoners' dilemma, the ultimatum game and its multi-player variant, and the survival game. The results showed that EIL could significantly improve cooperation, promote altruism behaviors, and stimulate the sense of fairness in the equal mode, whereas increasing the trend of self-interest gradually in the process of switching to other modes. To sum up, our model illustrates that empathy can act as a virtual drive underlying cooperation and competition. This provides novel methods and insights in regulating behaviors in multi-agent systems, as well as artificial subjects in psychology and behavioral economics experiments.