The marketing environment for books has become immensely more complicated and crowded than it was in the past. Partly due to the ongoing information explosion (which lets you and discuss this at all), marketing is increasingly "siloed", or targeted, because the sheer number of offers is now too much for a human to process in full, you need the tech that allows a million choices to also assist you in narrowing that million into a short list you can actually peruse. This applies to books, as well.
Most readers get this; they know where to look for the stories they like, and publishers limit their advertising for a story to venues where it is likely to sell.
Now some books truly are cross-generational; Harry Potter is written for a specific market, but has proven appealing to age groups far beyond that, into the adults and elderly. But it got there virally, initially it was marketed for its age group (about the same as the protagonist; Young Adult (12-18)). It gained popularity in other markets due to word-of-mouth, which BTW is also much amplified by the same tech that makes it difficult to stand out. "Going Viral" is new terminology, but is a little paradoxical: It is very difficult to stand out, but when something does stand out as truly worth sharing (for whatever reason), global communications technology can make the free recommendations explode into the millions.
If you can actually write something that will appeal to all age groups, pick a lane, a genre, that will make it easy to market to ONE easy group. An agent or publisher doesn't want to hear that your story appeals to absolutely everyone -- They can't afford to market to "everyone". (And nothing really does, you cannot appeal to a Middle Grade (8-12 yo) audience and also appeal readers of Erotic Fiction.)
If you think you have the skill, do what JK Rowling did; appeal to Young Adult, with a story that will appeal to a good segment of the readers over 18. Give the publisher something reasonably easy to market, and let virality sell the rest. The agent and the publisher will read your story, and you can trust them, as experts in the field, to realize there is potential for the book to escape the boundaries of the Young Adult market. But they need an affordable place to start, and you need to make sure your book will sell in one well-defined existing age group they understand, before you try to sell it to other age groups.