TLDR: I built an AI cowriter and director called Coweave to help anybody write interactive fiction, a task that until now required some knowhow of programming. There’s a video below if you’d like to watch, rather than read.
Interactive Fiction: A Short Personal History
I’ve always been personally very fascinated by interactive fiction. It’s at the intersection of a lot of things I love: amateur writing, reading fiction, and of course, programming. I’ve read (& still continue to read) a lot of books, and I’ve experienced some really amazing interactive fiction as well.
Interactive fiction is also important because it was the precursor to a huge industry: computer games. When all computers could do was display text, all computer games were text games, and there were some fascinating games developed during that period. Constraints are liberating after all.

I also feel there is this inverse relationship between imagination and specified detail. The more an author (or game developer) specifies how a thing looks or feels or is, the less you use your imagination. And the more detail you need to develop for a high-fidelity game, the less options a player can experience. You can’t ignore the princess and go after her pretty maid in Zelda, but if it’s a text game that’s more free-form, perhaps you can? Or at the very least, it’s cheaper to build in that option.

I believe that interactive fiction remains still relevant today because of a few reasons:
- With the mobile centric world we have now (& the reduced attention span that comes with it), a lot of users are used to scrolling down, and short paragraphs of text spliced with choices are a good way to explore a story.
- The above-mentioned imagination vs fidelity dropoff means that it’s cheaper to explore a lot more options if you have just text to generate.
- And finally, we now have a tool with generative AI that makes such text generation possible, and cheap.
Building Interactive Fiction Now
I’ve always felt that it’s a bit sad that building interactive fiction required some knowledge of programming. The most well known one is Inform, and this is what a program in Inform looks like.
Constant Story "Hello Deductible";
Constant Headline "^An Interactive Example^";
Include "Parser";
Include "VerbLib";
[ Initialise;
location = Living_Room;
"Hello World";
];
Object Kitchen "Kitchen";
Object Front_Door "Front Door";
Object Living_Room "Living Room"
with
description "A comfortably furnished living room.",
n_to Kitchen,
s_to Front_Door,
has light;
The friendliest one is probably Choicescript, but even that is not really non-programmer friendly:
Your majesty, your people are starving in the streets, and threaten revolution.
Our enemies to the west are weak, but they threaten soon to invade. What will you do?
*choice
#Make pre-emptive war on the western lands.
If you can seize their territory, your kingdom will flourish. But your army's
morale is low and the kingdom's armory is empty. How will you win the war?
*choice
#Drive the peasants like slaves; if we work hard enough, we'll win.
Unfortunately, morale doesn't work like that. Your army soon turns against you
and the kingdom falls to the western barbarians.
*finish
I think the fundamental problem is that interactive fiction has to be in some way modeled after the choices a player makes, and if that’s the case, you need some form of if-then-else
or some variables to set, and then you quickly lose folks who are just plain writers. And that’s a real shame. Look at the zillions of writers (& the hundreds of good stories) that are up on communities like RoyalRoad or Wuxiaworld. Is there a way to make interactive fiction accessible to them as well?
Coweave and working with an AI
One of the most prescient bits of writing I wrote on this blog was this one from over 20 years ago called Augmented Intelligence:
Instead of perpetuating a Man vs specific Machine in a special context, the focus will then change to the collaboration between Man and Machine. That would help everyone.
How can generative AI help non-programmer authors write interactive fiction? My solution is to interweave directions and choices right within the scene in plain English, for an AI to interpret:
# Scene 1: Jail Room
Anaka woke up in a dim, dark room. She could barely make out the door.
{{ if Anaka tries to open the door, respond that it's locked
unless she has the prison room key. if she looks around the
room or investigates, move to Scene 3. If she has the prison
room key, respond that the door is now unlocked, and move to Scene 2. }}
Anything between {{
and }}
is not considered scene text, but instead is interpreted by an AI. You can write pretty much anything in there. Here, I’ve added in a bunch of if cases and move conditions that look very similar to programming.
Here’s Scene 2:
# Scene 2: Escape
Anaka opened the door and stepped out. It's still dark,
but she can see moonlight slipping in from somewhere.
{{ the room has a staircase leading up, and it looks like
somebody (a guard?) walking to & fro upstairs. if anaka
goes up the stairs without sneaking, go to Scene 4. if
she does go up quietly without making much noise, go
to Scene 5. There is nowhere else to go and nothing
much to do. }}
There are if cases of course, but there are also constraints: There is nowhere else to go and nothing much to do.
and a special case where if Anaka is sneaking, there’s a different scene to move to.
There’s another capability unlocked by plain text like this, the ability to rewrite scenes. Jumping a bit forward, here’s Scene 5:
# Scene 5: To Kill or Not to Kill
She creeps up the staircase slowly and spots a guard,
with his back turned towards her. There's not too much
time, he'll spot Anaka soon.
{{ if Anaka hasn't dropped her knife, she can kill the
guard by sneaking up behind him and go to Scene 6.
if Anaka makes a noise or chooses not to kill the guard,
go to Scene 4 (change scene text to fit context) }}
The instructive words here are (change scene text to fit context)
. The AI can on-the-fly, dynamically rewrite Scene 4 to fit the new situation:

To recap: there are so many advantages of using an AI over programming an interactive fiction game:
- First, the intent is clear and understandable to anybody who knows English. I suspect that my constructs look like programming more because I’m a programmer, and a good writer can find better ways to jump around scenes.
- There’s no need to think about variables, or inventory or status screens. The AI just knows whether you have picked up or dropped a knife, whether you have the sneak skill or not, and what your status screen should look like based on your actions.
- And finally the ability to rewrite scenes based on context avoids a whole truckload of duplication when you go back to a scene you were in previously. You don’t need to rewrite the scene text, the AI will do it for you.
Show, Don’t Tell
I think that’s enough describing. In the vein of all good fiction, here’s a video where you can see how it works:
The AI as a Codirector
One surprising thing that’s unlocked is you can tweak how strictly the AI needs to stick to your script. AI has the ability to just stick to your story guidelines, but let the player experience the story the way they want to.
Here’s my wife Ammu playing the game, but she absolutely didn’t want to kill the first guard. Instead, she chose to negotiate:

You set the boundaries, let the player experience the story a completely different way.
How do I Run this Myself?
The code is OSS, so it’s available on Github here. Currently you need to be tech-savvy to run this (& you need to have an OpenAI key). You can find instructions here.
Some Technical Details
Just FYI: this section is just for me to geek out on how I built this: not necessary reading if you aren’t interested.
The Prompt
Really, all you need to experience this is ChatGPT and a prompt. Here’s a prompt that should work:
I want you to act as an interactive text fiction simulator.
I'll provide you with a set of scenes and instructions to parse
input from the user between {{ and }}. The text outside these
curly braces are scene descriptions to be shown to the user.
Only show one scene at a time. You can change the scene text
if it makes sense for the context, but make sure the intent is the same.
The only prompt you should display to the user is this: ">".
Don't say things like "Sure let's begin" or "Scene 1", respond
only with the scene.
---
# Scene 1
Anaka woke up in a dim, dark room. She could barely make
out the door.
{{ if Anaka tries to open the door, respond that it's locked
unless she has the prison room key. if she looks around the
room or investigates, move to Scene 3. If she has the prison
room key, respond that the door is now unlocked, and move to Scene 2. }}
[more story scenes here]
---
The final prompt I put into the app returns JSON output with more information (the current scene, the game state & so on), but this really is enough to get ChatGPT to work as an interactive fiction coauthor.
This is a Rails App
I decided to build this in Rails because it’s still the best way for a single developer to be productive and get started. This was true way back in 2005 or so when I first started using it, and it’s still true 20 years later. Nobody really needs the geekery of client-side JavaScript for prototypes, and I suspect even for a lot of larger apps, the new Turbo/Rails experience is superior.
I built most of the functionality—the CRUD, the OpenAI API integration, streaming responses just like ChatGPT in just about a day, and integrating Tailwind UI meant that I didn’t really have to worry about UI work a lot. It’s also seriously amazing that even in 2025, Rails can build a complex app like this with zero dependencies. The database? It’s sqlite, which is just a file. The job system? It’s now plain Ruby over sqlite called ActiveJob. The websocket implementation ActionCable only needs Redis in production: it uses an in-memory store in development. All this means that rails new
and you have everything you need to build apps. Which is refreshing coming in from full-stack JavaScript frameworks like Next or Remix.
There are things I miss from the React/Node world: static typing with TypeScript is definitely one of them, and the ability to just extract presentation views to components is another. Ruby seems to have solutions for both static typing and components, but they feel a lot clumsier (& bit early days) than both TypeScript and React.
ruby-openai
ruby-openai was a pleasure to work with. If you are thinking of prototyping AI applications, you don’t really need to start anywhere else. It also offers streaming support built-in, but the default linked example is more than a bit inefficient in how it thrashes the DB. I spent some time tweaking that to be a bit more efficient.
Turbo geekery
I really love the mental model of server-first apps. You build apps the “normal” way first, and ensure everything works with Turbo switched off. Then you progressively add in the interactive behaviors that you want. I also found that the default behavior in Turbo of prefetching links on hover, and replacing body content gets you almost 80% of the way there in making an app feel “instant”.
For streaming, the direct models broadcasting changes to the view mental-model that Rails seems to encourage seems a bit clunky at first, but it works well. I think this API could be a work in progress, as it’s more natural to have these in a controller.
Streaming JSON from OpenAI API
What do you do when you want to stream messages just like ChatGPT but also structured output from the OpenAI API? The problem is that streaming chunks of JSON can potentially lead to invalid JSON when parsed using a regular parser:
{"message": "Anaka is dead
Instead, I found a best-effort partial JSON parser called optimistic-json. You just have to remember to put the “most important” or streamable details first in your JSON response, and then parse it partially. This means that I’m able to both stream messages and display structured information like scene numbers, because the final JSON output looks like this:
{
"message": "Anaka is dead. Game over.",
"transition": "story_over",
"scene_number":4
}
Next Steps & Feedback
This was written as a hobby, and definitely not as an attempt to productize this somehow. I do wish that somebody will take this idea and run with it.
I also have a prediction: if and when generative AI progresses to have dynamically generated scenes rendered in real-time (Sora, but with enough live FPS that it’s game-ready), it’ll be amazing to see similar techniques used in RPG games. The developer just needs to hint at environment details for an AI to render from their combined imagination in real-time. Wonderful times ahead!

Do check out the code, or if you are non-technical, the video of how this works, and let me know any feedback. Thanks!
Leave a Reply