Within applications of swarm control, failing to maintain cohesion amongst the agents may lead to mission failure. We study the effect of limited sensing range of swarming agents when guided by a shepherd. A connectivity-aware approach is proposed to enhance the cohesion of the swarm. We combine a graph-based model of the flock with particle swarm optimization (assisted by DBSCAN) to improve the shepherd’s performance in herding sheep (swarm members). The approach is evaluated using multiple initial swarm configurations. Simulation results on swarm sizes of 50 and 100 agents show up to 50% reduction in the task completion time and an average improvement of 25% in the success rate for low density sheep initialization scenarios and competitive results for the higher density scenarios.