The advancement of UAV technology makes the use of UAVs more and more widespread, and the swarm is the main mode of UAV applications owing to its robustness and adaptability. Meanwhile, task allocation plays an essential role in a swarm to obtain overall high performance and unleash the potential of each UAVs owing to the complexity of the large-scale swarm. In this paper, we pay attention to the real-time allocation problem of dynamic tasks. We design models for the task assigning problem to construct the constraints model and assigning objectives. In addition, we introduce a novel agent-based allocating mechanism based on the auction process, including the design for three kinds of agents and the cooperation mechanism among different agents. Moreover, we proposed a new algorithm to calculate the bidding values of UAVs, by which the messages passed between UAVs can be reduced. On the basis of the assigning mechanism, we put up with a novel agent-based real-time task allocation algorithm named NECTAR for dynamic tasks in the UAV swarm. Furthermore, we conduct extensive experiments to evaluate the performance of our NECTAR, and the results indicate that NECTAR is able to solve the real-time task allocation for dynamic tasks and achieve high performance of the UAV swarm.