He sounds pretty certain this time. I know Phelps said he was done after 2012, but he wasn't thrilled with the way he left the sport. This time in Rio, he's thrilled with how his events and finals went, and with his role on the team etc. After his last relay, he said he couldn't have asked for more, so he really might be done this time.
It is very rare for professional athletes to come out of retirement more than once. Coming out only once is not a rarity; individuals like Brett Favre and Michael Jordan have come out of retirement in their sports, but later retired permanently. After winning so many medals, there is no reason for Phelps to tarnish his legacy by continuing to perform when his ability will decline in the future.
Michael Phelps is 31 years old, and he's been in five Olympic Games. I think he's had enough by now, and he knows that he's not going to have as much success if he comes back again. He's a father now, and it seems like he's content to move on with his life.
Micheal Phelps has said he would retire before, but he is currently at the top of his game. He is not going to retire unless he starts losing or it is too hard for him. Many athletes say they are going to retire and never really do because they miss the game.