Early access

LLM-driven choose-your-own-adventure

Technical details

Exo's CYOA is an LLM-driven choose-your-own-adventure that adapts to you. You describe your next move, and the game responds with new narration. Guide a party through dangerous places, talk to characters, inspect the world, collect gear, craft solutions and make choices that reshape the narrative. Behind the chat flow, a structured simulation — locations, entities, items, quests — grounds every action and remembers what you did.

Technical details

Stack overview

Modules

Exo's CYOA is split into a Spring Boot server and a desktop client. Both modules communicate via an OpenAPI using a local socket (loopback).

  • Server: Spring Boot 4 on Java 25, with large language model bindings, agentic turn orchestration, async streaming jobs, action execution, memory retrieval, and story generation.
  • Client: A desktop GUI that consumes the adventure API, renders the chat-style interface, and exposes locations, party, quests, editors, and helper modules.
  • game-engine: The modular 2D framework behind the GUI, including rendering, module lifecycle management, events, storage, input, audio, and localization. Forked and modernized from Spacecraft Tactics.
  • lm-lib: The reusable agent runtime and LLM integration library that powers model profiles, orchestration, tool-calling flows, streaming, token accounting, and response handling.

Public repositories

Open building blocks

The game engine and the language model library were released as open-source libraries on GitHub. The game-specific client and server modules build on top of those shared libraries.

Memory

Tiered Memory System

The adventure needs to remember context across long sessions without overwhelming the model. A three-tier memory system balances recency, importance, and semantic retrieval.

  • Tier 1, Recency: A sliding window of the most recent chat turns, kept within a token budget. This is the fast path, the model gets the last few exchanges in full, ensuring immediate context is always available.
  • Tier 2, Summaries: After each turn, MemorySummaryAgent distills the narrative into a concise summary, then ImportanceClassifierAgent scores it. High-importance summaries persist longer, low-importance ones evict first. Boundaries and sliding windows keep the tier bounded as sessions grow.
  • Tier 3, Hierarchical tag archive: A four-level tree that organizes content by boundaries (major story events), thematic or entity tags, and importance. TagDecompositionAgent breaks new content into tag groups with aliases, each scored for importance. Content is stored as MemoryTier3ContentRef leaves within importance buckets quantized to a configurable step size (e.g. floors of 10), so similar-importance summaries share a bucket. The system supports both story-narrative branches (grouped by tag) and entity-anchored branches (NPC, item, location, quest, character, connection), linked by UUID to domain objects.

Retrieval scores candidates using recency (newer boundaries first), importance (higher floors score more), and tag overlap with fuzzy matching via Levenshtein similarity. A token budget ensures only the most relevant summaries are returned, rendered as grouped prose with tag headers and location context.

When an importance bucket grows beyond a configured threshold and contains enough references, MemoryTier3Service automatically compacts the content using the LLM — similar summaries are merged into a single dense summary, preserving tag relevance. Compaction groups content by tag overlap into buckets first, so only semantically coherent sets are merged. Entity descriptions are always kept at maximum importance (100) and are exempt from narrative compaction.

Change tracking via MemoryTier3ChangeRef records which boundary, tag branch, or importance level was modified at what timestamp, enabling incremental diffing instead of full re-scans.

Memory budgets per tier are configured by MemoryConfigService, letting users trade token cost and available context size for recall depth.

Actions

Flow Actions

A player's instruction is classified into one or more actions from a taxonomy of roughly twenty action types. Each type has a dedicated flow agent that reasons about the decision, updates game state, and queues a narration request, separating the “what happens” from the “how it sounds.”

  • Two-phase processing: First, a flow agent (e.g. GoToLocationFlowActionAgent) makes structured decisions, parsing targets, validating feasibility, computing outcomes. Then a narration agent (e.g. StoryGenerationAgent) renders the result into prose. Deferred narration lets the system batch multiple actions into a single cohesive paragraph.
  • Dynamic dispatch: The OrchestrationAgent enqueues actions in a work queue and walks them one by one. An agent can enqueue derived actions mid-flow (e.g. travel triggers a carryover decision), or clear the queue (e.g. combat interrupts other pending actions). The game master phase replays the same pattern with a GM classifier and GM narration agent.
  • User confirmations: When an action is risky, leaving the party, destroying an item, something that can't easily be undone, the flow agent emits a UserConfirmationRequired update. The orchestration pauses, waits for the player's decision, then routes to the confirmed agent or to a decline-rewriting agent.
  • Entity lifecycle: Actions and narration that reference new entities (npc, item, location) flow through EntityRefAgent and EntityCreationAgent, which create the entities on the fly. Removals are gated by EntityRemovalConfirmationAgent, so the player is asked before something disappears.

Graph-Based Architecture

Graph-Based Agentic Flow

Exo's CYOA is built around an implicit agent graph where each node is a narrow-purpose agent and edges are determined at runtime. This design is intentional: smaller models on edge devices need focused prompts and strict harnesses to produce reliable results. Instead of asking one model to do everything, the system delegates each task to a specialist with a minimal, well-structured prompt.

  • Implicit directed graph: The AgentExecutorService in lm-lib performs a recursive walk. Each agent's chooseNextAgent() returns an AgentNext that names the downstream agent, the routing is data-driven, not hardcoded. The OrchestrationAgent in the server acts as the graph controller, driving a phase-based state machine (CLASSIFICATION → ACTIONS → STORY → MEMORY → DONE) and enqueuing specialized flow agents as pending work.
  • Narrow specialist agents: Over thirty purpose-built agents handle single tasks, classifying player intent, resolving entity references, executing travel actions, generating narration, scoring memory importance, decomposing tags. Each uses AgentType.COMPLETION (single-turn, no history) or a lightweight conversation, keeping prompts short and models predictable.
  • Parallel branching and merging: Template syntax [[key]] spawns parallel splits, one per list element, executed concurrently on separate virtual threads. After completion, merge() combines the results. This is used for entity reference resolution and tag decomposition where independent items can be processed in parallel.
  • Tool calls for structured decisions: Classification agents can use tool-calling mode where each taxonomy entry becomes a ToolDefinition. The model selects tools rather than producing structured text, reducing parsing failures on smaller models. Tool-calling classifiers support parallel tool invocations via ToolCallData.required().
  • Structured output handlers: Agent response handlers (JsonAgentResponseHandler, CsvAgentResponseHandler, AccumulateTextAgentResponseHandler) parse LLM output into typed data. A retry loop with reformulation prompts ensures reliability, if parsing fails, the agent re-asks rather than crashing the flow.
  • Grading loops: The AnswerGrader2 pattern routes an agent's output through a binary quality check. If the grader's score falls below threshold, the context loops back to the source agent with feedback, up to two retries. The AgentNext.gradingPassed flag lets downstream agents react to grading outcomes.
  • KV-cache optimization: Most agent interactions are KV-cache optimized, leveraging cached responses to reduce redundant computations, improving performance and reducing costs.

Adventure flow

Turn orchestration

This diagram summarizes how a player instruction becomes classified actions, state updates, memory work, narration, optional game-master follow-up, and streamed client updates.