SP

GameX: state after the first generated answer

agentssoftware-design

A generated answer leaves the application with decisions to make: what the user can review, how a revision changes state and what remains useful when a later step fails.

GameX combines a narrative workflow with a visual asset pipeline. A creator develops a premise into world lore, factions, characters, plot arcs and questlines. Character descriptions can then become concept art followed by an attempted 3D reconstruction.

This walkthrough covers the narrative workflow, revision semantics and partial success in the asset pipeline. It focuses on the contracts between generation, application state and the interface. The code excerpts are from the GameX repository and are shortened for reading.

Make approval part of execution

The web application uses Next.js and React with a Python FastAPI backend. LangGraph coordinates the narrative stages through shared state. The main path follows a dependency order: concept, world lore, factions, characters, plot arcs then questlines.

  1. Concept
  2. World lore
  3. Factions
  4. Characters
  5. Plot arcs
  6. Questlines

Each stage → review → continue or revise

Figure 1. Generation follows the dependencies between narrative elements. Review points let a creator change direction before later stages inherit the result.

The graph pauses after each major stage. The pause is declared when the graph is compiled rather than implemented in each node:

saga_agent = workflow.compile(
    checkpointer=memory,
    interrupt_after=["concept", "world_lore", "factions",
                     "characters", "plot_arcs", "questlines"],
)

The API provides separate operations to start the workflow, submit feedback, continue generation and retrieve state. The interface can render the current result and wait for a deliberate continuation.

That review step has a cost. It adds interaction and sequential latency. For a creative workflow, approving a premise before expanding it into a full narrative gives the creator a useful control point. The graph makes the pause explicit so the interface does not need to guess whether it is waiting for a model or a person.

Give generated results a shape

Narrative outputs use Pydantic models. A character has named fields for identity, appearance, motivations, relationships and gameplay mechanics. Later stages can refer to those fields directly. The visual pipeline can use them when constructing a character prompt.

A schema creates a structural contract between generation and the rest of the application. It can establish that a field exists with an expected type. Rendering no longer depends on splitting an arbitrary paragraph into pieces. Each stage is also exported as both JSON and Markdown, so the same structured result can feed another tool or be read as a document.

Structural validity does not establish narrative quality. A character can satisfy every field and still contradict the world lore. A motivation can be present but weak. The review point remains necessary because the schema and the creator assess different properties of the result.

Revision changes merge semantics

List-valued state exposes a small but consequential distinction. Forward generation can add material to an existing list. Regenerating a stage after feedback needs to replace the previous version.

Two operations can return the same data shape
User intentReturned shapeRequired update
Add another characterList of charactersAppend
Regenerate this castList of charactersReplace

Appending both results would leave the old cast beside its replacement. The model might follow the revision correctly while the application still shows duplicates or contradictions. The bug would be in state merging rather than text generation.

A replacement marker in the list update distinguishes regeneration from an ordinary append. The four list-valued stages (factions, characters, plot arcs and questlines) share one reducer:

def list_replace_reducer(existing, update):
    if not update:
        return existing or []
    if isinstance(update[0], dict) and update[0].get("__replace__") is True:
        return list(update[1:])
    return list(existing or []) + list(update)

The feedback endpoint prepends that marker for a regenerated list-valued stage. The reducer recognizes it and replaces the old list; ordinary updates append. This is a small shared convention between the endpoint and reducer.

The convention also creates coupling. A list whose first real item happened to carry the same key would be misread. Nothing in the type of the list announces that its first element is special. If more update modes become necessary, an explicit operation envelope would make the contract easier to inspect. The present point is that the operation must travel with the data when the data’s shape cannot explain its meaning.

Regenerate in place

Revision does not rewind the graph. When feedback arrives, the endpoint calls the current stage’s node function directly with the existing state, the new feedback and the updated history. It then writes the result back into the checkpoint:

result = node_func({**current_state, feedback_key: feedback,
                    "feedback_history": updated_history})
if current_stage in list_stages:
    result[list_key] = [{"__replace__": True}] + result[list_key]
saga_agent.update_state(config, result)

The graph’s next scheduled node does not change, so the workflow is still paused at the same review point after regeneration. The response reports that it is still awaiting feedback. A creator can revise a stage several times and only advance when they explicitly continue.

This design keeps the graph simple: it only knows the forward path. The cost is that regeneration runs outside the graph’s own execution, so anything the graph would normally do around a node has to be repeated or deliberately skipped by the endpoint. Keeping that list short is part of the contract.

Carry decisions forward

A revision request contains a decision about the creator’s intent. GameX records the feedback with its stage and a per-stage revision number, then makes that history available to regeneration and to every later stage.

For example, a request to keep a conflict local should remain relevant when the workflow moves from factions to characters. If the next stage sees only the original premise, it may expand the scope again even though the creator already rejected that direction.

Each node turns the history into a short block of earlier preferences in its prompt. It excludes the current stage’s own entries, which arrive separately as that stage’s feedback. It keeps the most recent six. That window is a simple bound on prompt size. It also means a decision older than six entries silently drops out of context.

Keeping history gives later stages access to the decision. It does not guarantee adherence. The history can grow, consume context and contain instructions that supersede earlier ones. A larger workflow would need a policy for summarizing preferences while keeping the current decision distinguishable from an obsolete one.

Use execution state for progress

Previously generated fields remain in shared state. Their presence says that content exists. It does not reliably identify the graph’s current pause point.

The backend therefore inspects the LangGraph snapshot and its next scheduled node. A small table maps each possible next node to the stage now awaiting review. If world lore is next, the concept stage has completed and the workflow is at its review point. An empty next set means the workflow is complete. That execution signal gives the frontend a basis for presenting the next action.

Separating content state from execution state helps during revisions. Old content can remain available for display while the workflow is waiting to replace it. A populated field should not make the interface announce that the current version has already been approved.

Speed and review pull in different directions

The agent also has a parallel execution mode that runs independent generation work concurrently. It is only used when automatic continuation is enabled, because concurrent stages cannot each stop for a person to approve them. If parallel execution fails, a configuration flag lets it fall back to the sequential workflow.

That makes the trade explicit. The interactive path gives a creator a decision at every stage. The automatic path is faster for a first draft but removes the review points that stop a rejected direction from spreading. The two modes produce the same data shapes, so the difference has to be visible in how the result is presented.

Represent partial success

The visual path, Nexus Forge, is a second LangGraph workflow. It synthesizes a visual prompt from the character and game context, generates concept art, runs a face-blending step that is currently a placeholder and then attempts a 3D reconstruction with SAM 3D on Modal. A successful reconstruction can be previewed and downloaded as a GLB file.

Image succeedsConcept art is available

Continue to reconstruction.

Reconstruction failsReturn the available image

Show a warning and restore reserved credits.

Figure 2. A concept-only result has a different completion state from a generated 3D model. The interface needs to preserve that distinction.

Each node records a status in the shared state: a generated prompt, a generated image, a generated model, a failed model or no usable image. A failed reconstruction keeps the image and adds a warning that concept art is ready but 3D reconstruction failed. If no valid image exists, the 3D step does not run.

The route handles an image-only outcome explicitly. If the parsed response contains concept art without a 3D model URL, it can return that art with a warning and restore the reserved credits. Handled generation failures also have a refund path. The refund restores credits only within the same billing cycle and reverses the daily usage count only on the same day, so a late refund cannot inflate a new period.

These paths make partial success visible, but they do not by themselves establish crash-safe billing. A process can fail between generation, persistence and a credit update. Reliable retries require the completion and refund operations to be safe when handled more than once.

A GLB export also needs a separate assessment before use in a game. Topology, rigging, animation and engine performance remain asset validation questions. Returning a supported file format does not answer them.

Make provider failures actionable

The Forge endpoint distinguishes provider failures instead of returning one generic error. A rejected API key or missing model permission returns a 502 with a message that names the setting to check. A quota or rate limit returns a 503, which tells the client that retrying later may work. Other provider errors and unexpected failures are logged with their traceback while the client receives a short message pointing to the backend logs.

The distinction matters for the interface and for billing. A rate limit is a reason to wait. A configuration error will fail again until someone changes the deployment. Treating both as the same failure would make the creator retry something that cannot succeed.

State the durability limits

Checkpoint support depends on the selected backend. The narrative graph attempts to use SQLite and falls back to an in-memory saver when that setup is unavailable. The fallback cannot preserve the same state across process restarts. A user-facing promise of saved progress needs to reflect which backend is actually operating.

A second limit sits above the checkpoint. The table that maps a session ID to its graph thread is an in-memory dictionary in the API process. With SQLite, a thread’s checkpoints survive a restart, but the session lookup that finds them does not. Durable progress needs both layers to persist.

The Forge billing store is a JSON file. Its reads and writes are serialized through a promise queue inside one Node.js process. The code marks this as a shortcut: the queue protects one server process only. Moving to multiple workers requires durable job records and transactional credit updates. Retrying an expensive job after a crash also needs a durable identity so the system can recognize a previous completion instead of charging or refunding twice.

The next engineering work follows from those boundaries: persistent sessions, persistent generation jobs, idempotent completion handling, transactional billing and observable stage execution. None of those properties can be inferred merely from the presence of an API route or checkpoint object.

GameX is useful to examine because the contracts are concrete. Approval belongs in execution state. Revision has a distinct merge operation. Feedback survives the stage that collected it. Partial output has a visible completion state. Those choices determine whether a creator can understand what the application is doing.

Scope and limitations

No throughput or latency benchmark is reported here. Checkpoint durability depends on the selected backend. Session lookup and billing currently assume a single server process. The face-blending step is not implemented. The repository’s stated use restrictions are not treated as an open-source license.