Question: why ryan left the office?
Answer: In the season 4 finale "Goodbye, Toby", Ryan is arrested for committing fraud. He is eventually released and required to work community service. In the season 5 premiere, Ryan returns to the Scranton branch after Michael arranges for him to work Pam's job.