Modified AgentService to avoid 100% CPU consumption in AgentService.