Building an AI Interactive Visual Novel with DeepSeek: A Complete Engineering Journey from Prompt to Agent

A Bilibili creator open-sources a DeepSeek-powered AI visual novel editor, revealing the full engineering path from Prompt to Agent.
A Bilibili creator built and open-sourced an AI interactive visual novel editor using DeepSeek, consuming roughly 1 billion tokens in training and debugging. The article contrasts two architectural paradigms — traditional node editors paired with LLMs versus a true Agent-driven system with memory and world-lore constraints — and details three core engineering pitfalls: character drift as prompt constraints decay over turns, memory chaos from poor context management, and the tension between world-lore enforcement and token cost control. The result is a game where characters genuinely remember player choices and deliver long-term narrative consequences.
From "Node Editor Wrapper" to Genuine AI Interaction
When people hear "AI interactive visual novel," many immediately think: isn't it just a large model slapped onto a node editor? That assumption significantly underestimates the engineering complexity involved. A Bilibili creator built a full AI interactive visual novel editor using DeepSeek and chose to open-source the entire process. By their own account, training and debugging alone consumed roughly 1 billion tokens.
The real value of this project isn't that it's "yet another AI narrative tool" — it's that it reveals the authentic path from simple prompting to a fully deployed Agent system, complete with every pitfall along the way.
Where Traditional Tools Hit Their Ceiling
Popular AI interactive visual novel tools like Castloop and Funloom are fundamentally combinations of "traditional node editors + LLM API calls." Creators drag and drop story branch nodes, while the model only fills in dialogue details. The limitation is obvious: players can only navigate within a predefined framework, with no genuine immersive free interaction.
The author offers a sharp analogy: a traditional node editor is like a fixed bus route map drawn in advance — players can only move between preset stops, choosing at most which connection to take. Story outcomes are exhaustively pre-specified; the AI is just a fill-in-the-blank tool.

Agent-Driven Galgame: A Completely Different Logic
If the goal is to build an interactive game in the Galgame format with Agent training genuinely baked in, the entire paradigm shifts.
Extending the earlier analogy, an Agent-based interactive game is like giving every NPC their own autonomous personal guide who can think independently. When you wander down a side alley and ask something completely off-script, the NPC can still respond in a way that aligns with the established story and their character — rather than breaking immersion by coldly declaring "that content isn't in the settings."

The fundamental difference is a paradigm shift from "preset branches" to "dynamic generation + constraints." The former is a finite state machine; the latter is an intelligent agent with memory and world-lore constraints. Every choice a player makes, every line they say, can be genuinely "perceived" and "responded to" by the NPC — rather than hitting an invisible wall in the script.
Agent in the AI engineering context refers to a model system that can perceive its environment, maintain state, autonomously plan, and execute actions — fundamentally different from a simple "question-and-answer LLM call." An ordinary prompt call is stateless, with each request independent of the last. An Agent system maintains contextual memory, tracks goals, and continuously adjusts its output strategy across multiple turns of conversation. In the game NPC scenario, an Agent means the character can not only answer the player's questions but also "remember" what happened earlier, "assess" whether the current situation fits the world-lore, and generate coherent responses on that basis. This is precisely why building a functional game Agent is far more complex than writing a well-crafted character prompt — it is fundamentally an engineering system requiring memory management, logical constraints, and cost control working in concert, not merely a matter of model capability.
Three Major Engineering Pitfalls
From writing the first character prompt to deploying a complete Agent system, the author documented three critical technical challenges — the most valuable lessons distilled from the entire project.
Pitfall One: Character Collapse
At the start, creators typically write simple character prompts. The result? The NPC eventually breaks character mid-game — one moment playing a medieval magic girl, the next suddenly dropping a contemporary internet meme. This is the most common loss-of-control problem in LLM role-playing: the constraining power of a prompt decays as conversation turns accumulate.

This phenomenon is technically known as Character Drift or instruction forgetting. The root cause lies in the attention mechanism of large language models: as conversation turns increase, the influence of early character constraints in the prompt gradually weakens, and the model increasingly follows the tone and style of the most recent exchanges. Additionally, internet language patterns are deeply embedded in training data, making models prone to "sliding back" into pre-training expression habits when certain high-frequency topics arise. Common engineering solutions include: periodically re-injecting character summaries into the context, running character-consistency checks on outputs, and fine-tuning the model to internalize a specific character at the weight level. This is precisely why the author needed roughly 1 billion tokens of training and debugging — a carefully crafted prompt alone simply isn't enough.
Pitfall Two: Memory Chaos
The solution to character drift is equipping the Agent with a layered memory mechanism. The author's approach separates three categories of information:
- Main storyline key events: Written into long-term memory, retained persistently;
- Recent interaction details: Stored in short-term memory, available for immediate retrieval;
- Core character settings: Serving as a stable character foundation.
This design mirrors how human memory works — important things are remembered for a long time, while recent minor events are held temporarily. With layered memory, an NPC won't suffer narrative breaks like "forgetting you saved them earlier."
Layered memory architecture is the mainstream design paradigm in current Agent engineering, typically corresponding to three storage layers: Long-term Memory handles the persistence of key events and character relationships, usually stored in a vector database and retrieved on demand via semantic search; Short-term Memory refers to recent dialogue within the current context window, directly participating in each model inference pass; Character Profile serves as a static anchor, ensuring that personality and world-lore constraints are always active. The engineering challenge of this architecture lies in two areas: deciding which information is worth writing to long-term memory (too much causes retrieval noise; too little leads to narrative breaks), and efficiently assembling all three layers into an effective prompt at inference time while keeping total token count within the model's context window limit. This is the core complexity of the "memory chaos" pitfall.
Pitfall Three: World-Lore Violations and Cost Runaway
Beyond memory, you also need dynamic validation of actions and story branches to prevent Agent-generated content from straying outside the game's world-lore framework. At the same time, you must manage running costs — you can't let every interaction burn through massive amounts of compute, or ordinary players simply won't be able to run it.
This point is especially critical. Many AI applications deliver impressive demos, but once you account for scale and cost, the token overhead per interaction turns out to be unaffordably high. The core of engineering a production-ready system lies precisely in finding a sustainable balance between "experience quality" and "cost."
Token cost is one of the most central engineering constraints in scaling LLM applications to production. With mainstream commercial models, inference costs are directly tied to total input + output token count. A game Agent with a full layered memory system may need to pack long-term memory summaries, recent conversation history, character settings, and world-lore rules into a single context — easily reaching thousands to tens of thousands of tokens per interaction, costing several to dozens of times more than a bare prompt call. Common engineering optimization strategies include: compressing long-term memory into summaries rather than full recall, implementing tiered response logic (lightweight models for simple interactions, high-performance models only at critical story nodes), and splitting world-lore validation into a separate low-cost classification task rather than delegating it to the main model. These optimizations directly determine whether an AI interactive game can survive at real user scale.
The Final Result: Characters That "Remember" You

After this full engineering journey from prompt to complete Agent system, the characters in the Galgame can now genuinely "remember" every change brought about by your choices. A small, seemingly offhand act of kindness might surface as an unexpected reward in a hidden storyline much later.
This design — where actions carry long-term consequences — is what makes interactive storytelling so compelling. Players are no longer passive observers of a script; they are genuine participants in the evolution of a world.
Closing Thoughts: The Next Chapter of AI Gaming
The significance of this open-source project may lie less in how polished it is, and more in the fact that it lays out a complete technical path for everyone to see — from prompt engineering and memory layering to world-lore validation and cost control. Every step is a milestone that AI application engineering must pass through.
For developers looking to enter the AI interactive storytelling space, this is a rare and practical reference. For the industry as a whole, it also confirms a trend: competition in AI gaming is shifting from "who can integrate a large model" to "who can build solid Agent engineering." What's the most immersion-breaking AI response you've ever encountered in an interactive game? Behind it almost certainly lies an engineering problem that hasn't yet been solved.
Related articles

Insufficient Source Material to Generate a Valid Article
The provided source material is a single unrelated tweet with no AI or tech relevance — insufficient to support a complete, valid technical article.

Insufficient Source Material to Generate a Valid AI/Tech Article
This source material is a tweet about the ages of Underworld members — unrelated to AI or tech, and insufficient to support a full article.

Insufficient Material: Unable to Generate a Valid AI/Tech Article
The provided material is a condolence tweet about a San Diego mosque attack — unrelated to AI/tech and too limited to generate a valid technical article.