Heat butter in a large oven-safe skillet over medium heat. Add onions, salt, pepper, and thyme. Cook for about 30 minutes, stirring often, until caramelized. Stir in garlic and turn off the heat.
While onions cook, boil pasta shells in salted water according to package directions. Drain and let them cool on a baking sheet.
Preheat oven to 400°F.
In a bowl, mix ricotta, egg, Gruyère, parmesan, salt, pepper, and thyme. Add half of the caramelized onions and stir to combine.
Fill each shell with the ricotta mixture.
Heat the remaining onions in the skillet, stir in flour, and cook for 1-2 minutes. Gradually add stock and cook until thickened. Stir in cream.
Place filled shells in the onion sauce, open-side up. Top with mozzarella and breadcrumbs.
Bake for 20-25 minutes until golden and bubbly. Serve with extra parmesan and fresh herbs.