Bagheera serves as Mowgli's guide and mentor, teaching him the ways of the jungle and helping him navigate the challenges and dangers that arise throughout the story.