NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Teaching a Story-Game Generator the Rules of Its Engine

Branching stories are expensive because writers must author every branch. Ten binary choices already produce 1,024 scenes, and a player sees only ten of them. Recent systems hand this work to a large language model. STORY2GAME is the most complete example: it turns a plot into playable Python code for a text adventure, and when a player tries an action the author never anticipated, it writes new code on the spot saying when that action is allowed and how it changes the world. The code almost always runs. Compile rates are 93–97%, and about 80% for the code written on the fly. But only about 60% of those on-the-fly actions behave sensibly. The system also breaks when the same object is called "Key" in one place and "Metallic Key" in another, because it then tracks two objects where there should be one. The bottleneck has moved. Writing prose is no longer the hard part. The hard part is producing world logic that stays consistent.

This note proposes a fix based on multi-task learning, meaning one network trained on several related objectives at once so that it learns internal representations useful to all of them. A symbolic text-game engine such as TextWorld can label two things automatically and in unlimited quantity: what the world looks like after any command, and which object each mention refers to. We will fine-tune a mid-sized open model to write action code, and train it at the same time on these two engine-labeled side tasks. The claim is that this joint training teaches the model how world states change, and that knowledge raises the share of generated actions that behave correctly. Two things must be ruled out. The gain must not come merely from extra data, and it must not be something a cheap post-hoc fix to the prompting pipeline would deliver just as well.

Core Claim

Training on engine-supervised next-state prediction and entity linking alongside action-code generation will raise the semantic correctness of generated actions on unseen action types. It will also cut duplicate-entity errors to near zero. The model should beat both a code-only fine-tune given the same number of training tokens and a prompted pipeline that adds name normalization and execute-and-retry. The mechanism we expect is measurable: hidden states of the jointly trained model should encode object properties more accurately, and that accuracy should track action correctness.

Relation to Prior Work

The work that motivates this proposal is the pipeline line. STORY2GAME chains GPT-4o-mini calls (events, then map, then code). NarrativePlay chains separate extraction, image and speech services. Bringing Stories Alive builds a knowledge graph by question answering and then generates descriptive text with GPT-2. None of these trains any shared representation across subtasks. That is exactly where their consistency failures arise, and it is what we change.

Two papers supply the method. Transfer Learning for Neural Semantic Parsing showed that sharing a sequence-to-sequence model between a structured-output task and an auxiliary task helps most when target data is scarce: up to +4.4% absolute accuracy at 10k examples, and +2.5% on ATIS from syntactic parsing. Its tasks were single-sentence parsing; ours involve world states that change over time. Exploring Story Generation with Multi-task Objectives in VAEs added topic and discourse side-losses to a story generator. It worked on short stories but lost its advantage on long ones, and it never modeled state or choices. We borrow its idea of auxiliary objectives. Our auxiliary labels are different: they come from an executable engine rather than from topic models or corrupted text, so they encode facts that can be checked.

One paper constrains the design. RotoGrad documents negative transfer, where tasks pull the shared weights in conflicting directions and joint training hurts. We therefore treat interference as something to measure rather than assume away. We also test whether gradient balancing is needed at all, instead of building it in.

Research Program

We will build training data from TextWorld's procedurally generated games. In those games, each rule is a precondition/effect pair, for example "unlock door requires holding the matching key and changes locked to unlocked." We will render each rule mechanically as a Python handler in the STORY2GAME code format. This gives correct target code for free. The same games also yield two labeled datasets:

  • State-transition examples: a current state and a command, labeled with the facts added and removed.
  • Mention-linking examples: a textual mention, which may be a paraphrase such as "the brass key," labeled with the canonical object it refers to in the current state.

The model is an open 7–8B decoder fine-tuned with low-rank adapters. Each task is marked by a prefix. The objective is

$$\mathcal{L} = \mathcal{L}_{\text{code}} + \lambda_s \mathcal{L}_{\text{state}} + \lambda_\ell \mathcal{L}_{\text{link}},$$

where $\mathcal{L}_{\text{code}}$ is next-token loss on handler code, $\mathcal{L}_{\text{state}}$ is loss on the serialized added and removed facts, and $\mathcal{L}_{\text{link}}$ is loss on the linked object identifier. The weights $\lambda_s$ and $\lambda_\ell$ are tuned on a validation split. Batches mix the three tasks in fixed proportions.

Fan et al. found that fully shared models can fail when tasks need very different outputs. To test whether that matters here, we will compare full sharing with a variant that has a separate low-rank adapter per task.

The test domain is deliberately broader than TextWorld's cooking and treasure-hunt rules. We will evaluate on off-script actions from STORY2GAME-style games built from MoPS premises and Wikipedia fairy-tale plots. Action verbs that appear in training are excluded from these tests.

For the mechanistic check, we will train linear probes on hidden states to predict entity properties, following the TextWorld state-probing setup (state probes). We then ask whether probe accuracy rises under joint training and whether it predicts which handlers are correct.

Baselines

The naive reference point is the STORY2GAME pipeline as published, with GPT-4o-mini and no training. Its reported semantic success rate is about 60%, with 93–97% compile success and about 80% compile success for dynamic actions (STORY2GAME). We will rerun it on our test actions so that it is judged by the same metrics.

The strongest existing competitor is a strengthened version of that pipeline, built by us because no published system combines these pieces. It adds a name-normalization step that maps each new mention to an existing object by asking the model to choose from the current object list. It also adds an execute-and-retry loop: a handler is regenerated, up to three times, whenever it crashes or leaves the world in an invalid state. This is the obvious cheap fix for both of STORY2GAME's failure modes, so it is the bar that matters. It gets the same number of model calls per action as our system is allowed at inference, plus the retries. We report its cost in tokens.

The key ablation is a code-only fine-tune of the same open model. It sees as many training tokens as the multi-task model, and the extra tokens are additional handler code rather than state and linking examples. If joint training wins only because it sees more data, this baseline will expose it.

A second ablation is sequential: train on state and linking first, then on code. This separates training on both tasks at once from training on them in sequence. Wang et al. report that intermediate training of this kind can overwrite earlier knowledge.

All fine-tuned variants share the same base model, adapter rank, and hyperparameter-search budget, with 20 trials each. The proposal counts as beating a baseline if it improves held-out semantic correctness by at least 5 absolute points, with a bootstrap confidence interval that excludes zero.

Why not just…?

Why not just add a name-normalization step to the prompting pipeline? Such a step may well remove the "Key"/"Metallic Key" duplicates, and we expect it to come close to our model on that metric. But duplicate names are only part of the roughly 40% semantic failure rate. Handlers that compile yet have absurd effects are untouched by renaming. We therefore report duplicate-entity rate and wrong-effect rate separately. If the strengthened pipeline matches us on both, the claim is false, and we will say so.

Why not just execute and retry until the code works? Retrying catches crashes and invalid states. It cannot catch an effect that is legal but wrong, such as eating the lantern and the lantern then glowing. For a novel action at play time, no ground-truth effect exists to check against, so the verifier has no signal on the failures that matter most. The comparison measures exactly this. Retry should close the compile gap and leave the semantic gap.

Why not just fine-tune on more handler code? This is the most serious threat. It is the data-matched code-only baseline. If that baseline matches the multi-task model on unseen action types, the auxiliary tasks contribute nothing beyond data volume, and the probe analysis should show no difference in what the hidden states encode either.

Why not use a larger prompted model? Larger models may raise the 60% figure, but at a cost per action that interactive play may not tolerate. We will include a larger prompted model as a reference and report its cost. We found no reported result on Lacuna for larger models on the STORY2GAME action suite.

Proposed Experiments

There are two automatic metrics on held-out action types, both computed in the engine. The first is state-match accuracy: execute the generated handler and compare the resulting state with the engine's own rule, where such a rule exists. The second is duplicate-entity rate across a full playthrough. Semantic plausibility for story-domain actions has no engine label, so it will be judged by human raters on a blind sample of 300 actions, with an LLM judge reported alongside as a secondary measure.

Interference will be measured directly. For each task we compare the multi-task model with its single-task counterpart, and we check whether the side tasks degrade the descriptive text the handlers emit. If they do, we test whether simple loss reweighting suffices before trying RotoGrad's rotation. The scaling question from Toward Automated Quest Generation and TextWorld's Treasure Hunter levels will also be revisited: does the advantage grow as games go from 5 to 20 rooms, where pipelines and agents are known to degrade?

The decisive check has three parts. First, the multi-task model must beat the data-matched code-only fine-tune and the strengthened pipeline on state-match accuracy for unseen actions. Second, it must achieve this at lower inference cost than the pipeline. Third, probe accuracy on entity state must rise together with handler correctness. If the first part fails, the idea is wrong. If only the third fails, the gain is real but our explanation of it is not.