Like many people, Miguel Roca had long struggled to fall asleep. Podcasts helped, sometimes, soft voices narrating history or science, but they were inconsistent. Episodes were too sporadic or too random. One night it might be soothing; the next, a deep dive into a topic that only sharpened his focus instead of easing it.

So he began to wonder: what if the story could be tailored, not just to a general audience, but to him?

That question led to  Stories for Sleepless Nights, an AI-driven system that generates personalized bedtime stories designed to calm the mind. It was, at first, a way to learn. As a current student in the University of Chicago’s Master’s in Applied Data Science program, Roca had set out to deepen his understanding of AI agents, particularly with tools such as LangChain and LangGraph.

But learning alone wasn’t enough motivation. He needed something personal, something that would keep him returning to the project night after night.

“I knew if I wanted to stick with it,” Roca said, “it had to solve a real problem for me.”

The earliest version was simple: a single AI agent that could take a prompt, say, a story about mythology or nature, and turn it into a structured narrative. The system would outline chapters, draft the story, and convert the text into audio.

The project expanded from there into a network of specialized agents. One recommended story ideas for nights when inspiration ran dry. Another generated custom visuals for YouTube and Spotify, after painstaking rounds of prompt engineering to achieve a consistent, calming aesthetic. A third automated the process of stitching together audio and imagery into video, eliminating the need for manual editing.Each addition solved a specific problem..

“It was always like, ‘What do I need next?’” he said. “And then figuring out how to solve that.”

The hardest part wasn’t building the system itself. It was shaping the experience.

A bedtime story, Roca realized, requires a delicate balance. Too dull, and the mind wanders back to the day’s anxieties. Too engaging, and sleep becomes impossible.

“It has to be interesting,” he said, “but also soothing. That balance was difficult.”

Even the voice mattered. Early attempts using commercial text-to-speech models proved either too costly or too rigid. Eventually, he found an open-source model, Kokoro, that allowed him to fine-tune tone and pacing. He slowed the narration slightly, adjusting it until it felt natural: calm, but not sluggish; engaging, but not stimulating.

There were setbacks. At one point, the system began reading out formatting artifacts, literally saying “asterisk, asterisk” when encountering bold text. Fixing those issues meant testing the product in the most literal way possible: by trying to fall asleep to it.

“It was a challenge,” he said, laughing, “because sometimes I couldn’t sleep, not because of the story, but because I was thinking about what I needed to fix.”

While much of the technical foundation came from prior experience, one moment in the classroom proved pivotal. In a Natural Language Processing course, the professor, Ignas Grabauskas, demonstrated a multi-agent system with a simple interface built using a tool called Chainlit. Until then, Roca had been running his project through code, which was functional but not easily shareable.

Within days, he rebuilt the interface.

The response was immediate. A project that had begun as a personal experiment suddenly felt like something more: a fully realized system, with a name, a narrator “Luna,” and a growing presence on platforms like YouTube and Spotify.

Still, he doesn’t plan to dwell on it for long. Roca is already thinking ahead.

His next idea tackles another everyday frustration: deciding what to eat. The concept is an AI agent that generates weekly meal plans tailored to dietary needs—gluten-free, organic, time-constrained—while also producing a corresponding grocery list, even customized to specific stores like Trader Joe’s.

It’s more ambitious. It may require building a full application, complete with a user interface that works beyond his own machine. It introduces new technical challenges, but the philosophy remains the same.

“The best projects,” Roca said, “are the ones that come from something you actually need.”

arrow-left-smallarrow-right-large-greyarrow-right-large-yellowarrow-right-largearrow-right-long-yellowarrow-right-smallclosefacet-arrow-down-whitefacet-arrow-downCheckedCheckedlink-outmag-glass