Hierarchical Reinforcement Learning for Optimal Agent Grouping in Cooperative Systems