Usually for a transition period, commonly three to twelve months, and longer where the buyer perceives owner dependence. The length is negotiable and shortens as the company demonstrates it runs without you.
More detail
Strategic buyers with their own management depth often want a short handover. Private equity buyers frequently want the owner to stay longer, sometimes with rolled equity, because they are buying a management team as much as a business. Individual buyers usually want the longest transition, because they are learning the business. The terms to settle in the letter of intent are the duration, the time commitment per week, the compensation, and what happens if either side wants out early. Owners who have built a management layer negotiate short transitions from a position of strength; owners who are still the center of the business negotiate long ones from weakness, which is another reason the preparation work pays.