Major refactoring: add agents join/leave handling