Agent-based Leader Election, MST, and Beyond