fix the shutdown process of the agent