Automated Guided Vehicles (AGVs) have played an important role in modern factories or warehouses, replacing traditional conveyor-based sorting systems due to their flexibility and scalability. However, existing works on AGV sorting systems primarily focus on improving performance from mechanical perspectives or network optimization for routing design. There is a lack of discussion on how to provide a holistic assignment strategy that considers not only the assignment at the sorting area but also the impact of traffic flow from upstream stations in the system. This study introduces a novel two-stage optimization model for AGV sorting systems in central fill pharmacies, implemented via a simulation-based heuristic algorithm. The methodology is based on a detailed analysis of the sorting system layout, assessing performance through key performance indicators (KPIs) such as throughput, utilization, and cycle time, complemented by a sensitivity analysis regarding the number of AGVs. Results demonstrate broad applicability across different automated systems, suggesting significant implications for operational efficiency.