Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIScientists Dev WorldSeed DMContextBuilder build

From Leeroopedia
Knowledge Sources
Domains LLM, Game_AI
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete context builder that assembles omniscient world state — all entities, recent events, target history, scene description, and domain knowledge — into a structured DMContext for LLM Dungeon Master judgment.

Description

The DMContextBuilder class gathers full world state for the DM. The DM is omniscient: it sees every entity and recent event, with no visibility filtering. All data is formatted as plain text for LLM comprehension.

Key methods:

  • build: Assembles DMContext from world state + action for standard DM judgment
  • build_gm_resolve: Assembles DMContext for GM natural-language commands, with broader allowed operators and `prompt_mode="gm_resolve"`

Entity formatting groups agents separately from other entities. Event formatting shows the last 5 ticks as one-line summaries. Target history shows the last 10 events involving the action's target entity.

The builder carries a `language` attribute that controls narrative language output.

Usage

Import this class to build DM context. In production, it's created by `TickEngine.__init__()` and used by `resolve_dm()` and `resolve_gm_command()`.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/dm/builder.py

Signature

class DMContextBuilder:
    def __init__(
        self,
        store: StateStore,
        event_log: EventLog,
        config: SceneConfig,
    ) -> None: ...

    def build(
        self, action: ActionSubmission, dm_config: DMConfig, tick: int,
    ) -> DMContext: ...

    def build_gm_resolve(
        self, text: str, tick: int, target_entity_id: str | None = None,
    ) -> DMContext: ...

Import

from worldseed.dm.builder import DMContextBuilder

I/O Contract

Inputs

Name Type Required Description
action ActionSubmission Yes Action being judged
dm_config DMConfig Yes DM config (hint, allowed_ops, max_effects)
tick int Yes Current tick

Outputs

Name Type Description
return DMContext Assembled context with world_state, events, etc.

Usage Examples

from worldseed.dm.builder import DMContextBuilder

builder = DMContextBuilder(store, event_log, config)
builder.language = "en"

# Build context for action DM
ctx = builder.build(action, dm_config, tick=5)
# ctx.world_state, ctx.recent_events, ctx.target_history, etc.

# Build context for GM command
ctx = builder.build_gm_resolve("Create a storm", tick=5)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment