I recommend you to check out the previous parts if you don’t know what this “neural narratives” thing is about. In short, I wrote in Python a system to have multi-character conversations with large language models (like Llama 3.1), in which the characters are isolated in terms of memories and bios, so no leakage to other participants like in Mantella. Here’s the GitHub repo.
As I mentioned recently, I realized that I hadn’t taken into account that all stories that would play out through this app wouldn’t take place in the same “world,” which at some point it had come to mean mechanically a single planet. Rather obvious in retrospect. So I had to program in the overarching notion of a Story Universe. Along the way, I realized I would need to tinker with plenty of other parts of the app that I dreaded touching, mainly the chat system and the classes that interact with the large language models (the AI). Those were the first ones I programmed in, so they were a mess. Thanks to the vulture library, that finds unused code in a project, I’ve removed every single remnant of the initial implementation, and now the chat system is very sturdy.
I intended to write an app focused on offering the user (mainly me) the choice to experience stories through it, but I was spending plenty of time programming code to interact with the AI and parse out its responses. I figured that there should be some industry-standard libraries out there to save me the trouble, and indeed there are two: pydantic and instructor. Pydantic lets you create “response models” without having to write JSON files; it handles all the parsing by itself, programmed by far more intelligent people. Instructor wraps the OpenAI API and offers compelling functionalities on top of it, such as retries, validators, streaming, etc. Check out its website.
Anyway, it has taken me days to return the app to a usable state, but now it’s far more robust, bolstered by about 400 tests, and the changes will allow me to introduce new actions, pages, etc. far faster.
Anyway, let’s get back to my first serious playthrough, focused on exploring the edges of the system to figure out what stuff I should program in.
My protagonist meets with his two allies, his partner and Elizabeth’s distraught father, in the rainy streets of Providence.
A few days ago I programmed in a new type of action, named Gather Supplies. As I mentioned in the past, every kind of action that could come up in a story, and that wouldn’t get resolved through a dialogue, I intend to program it in. Here is the narrative and the outcome of the team’s efforts to gather supplies for this endeavor.
As with any other action, the AI is prompted to enter the player and their followers’ personalities and general resourcefulness into the equation when coming up with the resolution.
Both teams gather at night in the outskirts of Providence, ready for a trip into the unknown. Elara has brought an acquaintance of hers, a middle-aged professor named Thaddeus Armitage.

Are those fused fingers I spy? Quite eldritch, I’d say.
Next up, adding a new area to the map and traveling to it, which will involve an audible narrative.
Pingback: Neural narratives in Python #15 – The Domains of the Emperor Owl
Pingback: Neural narratives in Python #17 – The Domains of the Emperor Owl