Urgent.News

What's breaking now, across hundreds of outlets.

Culture

Branching narrative without branches: how our AI story engine works

Building a branching narrative without branches: how our AI story engine works Classic interactive fiction — Choose Your Own Adventure books, text quests, visual novels — all share the same structural problem: somebody has to write every branch. The content cost grows exponentially with player freedom, so in practice "choices" converge back to a handful of scripted endings. When we started…

Crafting immersive interactive stories without the traditional branches presents a unique challenge. Interactive fiction, whether it's the classic Choose Your Own Adventure books or modern text quests and visual novels, faces the problem of content cost scaling exponentially with player freedom. This has led to a situation where most "choices" ultimately converge on a limited number of scripted endings.

Recognizing this limitation, Interactive Stories (Интерактивные истории) decided to abandon the traditional branching narrative structure altogether. Instead, they opted for a world state, a cast of characters, and an LLM that generates the next scene based on the player's actions, including those that were never anticipated by the creators.

The architecture behind this innovative approach can be summarized as follows: Players can choose a story from various genres like mystery, fantasy, detective, or survival, and are presented with an opening scene along with 2-3 suggested actions. However, there's always a fourth option: players can simply type anything they desire.

This could range from something as outlandish as "Burn the house down" to "Call my mom" or even "Challenge the ghost to a dance-off". The system accepts these inputs and weaves them into the story, determining the consequences based on the LLM's interpretation. The technical implementation relies on a technique called streaming generation.

The model's response is streamed to the user's device over Server-Sent Events (SSE), allowing the text to appear progressively, similar to a typing indicator on messenger apps. This approach ensures that perceived latency is more important than total latency. If the first words of the generated text appear within approximately 2 seconds of the player's action, the immersive experience is maintained.

The server retains the story's state, so even if the user uninstalls and reinstall the app, the progress of their story run is preserved. This also allows Interactive Stories to accurately meter usage, as the first 12 generations of each story are free. After that, users need to unlock the story with a one-time cheap purchase. In the early stages of development, the client's count for tracking usage was trusted, which proved to be highly exploitable.

This led to a lesson that usage should be metered server-side. The essence of this innovative approach lies in how players interact with the story. The first thing every player does upon starting a new run is to try to break the game. This is not a bug, but rather a fundamental part of the game design. When users type absurd inputs like "I pull out an accordion and start playing", and the story accommodates these actions, they become hooked.

The AI's ability to handle and incorporate such inputs seriously is the core delight of the experience. The second notable behavior of players is their emotional investment in the story. Unlike scripted fiction where characters' decisions are predetermined, the AI allows players to make genuinely their own decisions. This level of agency leads players to blame themselves for bad endings, a reaction that, in fact, is a compliment to the depth of the narrative engagement.

A key takeaway from this approach is that free input surpasses the utility of suggested actions. Suggestions are mainly there to teach new players that their input is valued and welcomed. Experienced players, however, prefer to type their commands freely. Another crucial lesson is that latency plays a vital role in the immersive experience.

Streaming the response instead of batching it allows for a smoother, more engaging narrative flow. Lastly, it's essential never to trust the client for anything that incurs costs - this includes metering, pricing, and content parameters. All such aspects must be handled server-side to ensure fair and honest usage tracking. The app is currently live on the RuStore, the Russian Android store, and you can find it at this link: https://www.rustore.ru/catalog/app/com.SpeedOfLightGames.AIbook.

If you have any questions about the narrative state management or other aspects of the system, the developers encourage you to ask in the comments.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Get the news by email. Yesterday's most-covered stories, every morning.

See today's edition · More options

More in Culture

More from Saturday, 5 December 2026 →