In this paper, a novel approach to design a photonic crystal exclusive-OR (XOR) gate with high performance using recurrent neural network (RNN) is proposed, integrating the principles of symmetry and asymmetry inherent in photonic structures. The proposed model realizes the nonlinearities and dispersion properties in photonic systems, optimizing the waveguide paths and interference patterns to improve the performance of the logic gate. Simulation results demonstrate that the presented RNN design not only achieves high fidelity in the logical operation but also significantly enhances the functionality of the all-optical gate. This integration of machine learning with photonic crystal technology opens a new era for developing compact, energy-efficient photonic circuits for high-speed optical computing. Finally, the performance of the designed all-optical gate is compared with other related methods, which shows that the proposed gate outperforms other works. The results show that the obtained output power of the proposed all-optical XOR gate is 0, 0.813, 0.82, and 1 × 10−7 in the logical states.