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 dm resolver

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

Overview

Concrete DM judgment resolution pipeline that calls an LLM provider, validates and sanitizes returned effects, and applies them atomically with rollback-on-failure, including action DM, consequence DM, and GM command resolution modes.

Description

The dm_resolver module (633 lines in `engine/dm_resolver.py`) contains several key functions:

  • sanitize_dm_effects: Adds safety defaults (e.g., `min:0` for decrement effects missing min).
  • validate_dm_effects: Checks count limits, allowed operators, entity existence. Returns `(bool, str)`.
  • resolve_dm: Action DM resolution — builds context, calls provider, validates, applies. Retries up to 2 times with error feedback.
  • resolve_gm_command: GM natural-language command resolution via DM.
  • resolve_consequence_dm: Consequence-triggered DM resolution (no agent).
  • apply_dm_response: Atomic effect application with snapshot/rollback. Delivers narrative as whisper or scoped event.

The retry loop sends validation errors back to the LLM via `dm_ctx.error_feedback`, enabling self-correction. On all-attempts failure, a fallback narrative ("The outcome is unclear.") is whispered to the agent.

Usage

Import these functions when implementing custom DM resolution. In production, called by `RulesEngine.resolve_dm_async()` and `TickEngine` during tick processing.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/engine/dm_resolver.py

Signature

def sanitize_dm_effects(effects: list[EffectConfig]) -> None: ...

def validate_dm_effects(
    effects: list[EffectConfig],
    dm_config: DMConfig,
    store: StateStore,
) -> tuple[bool, str]: ...

async def resolve_dm(
    action: ActionSubmission,
    dm_config: DMConfig,
    ctx: dict[str, Any],
    tick: int,
    dm_provider: DMProvider,
    dm_builder: DMContextBuilder,
    store: StateStore,
    event_log: EventLog,
    recorder: RunRecorder | NullRecorder | None,
    inbox_manager: InboxManager | None = None,
) -> None: ...

def apply_dm_response(
    *,
    response: Any,  # DMResponse
    store: StateStore,
    event_log: EventLog,
    ctx: dict[str, Any],
    tick: int,
    dm_scope: str,
    narrative_recipient: str | None,
    narrative_event_type: str = "dm_narrative",
    narrative_source: str = "dm",
    narrative_ttl: int = 3,
    inbox_manager: InboxManager | None = None,
) -> bool: ...

Import

from worldseed.engine.dm_resolver import (
    resolve_dm, apply_dm_response,
    validate_dm_effects, sanitize_dm_effects,
    resolve_gm_command, resolve_consequence_dm,
)

I/O Contract

Inputs

Name Type Required Description
action ActionSubmission Yes Action requiring DM judgment
dm_config DMConfig Yes DM config (hint, allowed_ops, max_effects, scope)
dm_provider DMProvider Yes Async LLM judge provider
store StateStore Yes Entity store for validation and effects

Outputs

Name Type Description
(mutation) StateStore Effects applied atomically
(mutation) EventLog Narrative event emitted
(mutation) InboxManager Narrative whispered to recipient
recorder record "dm_call" Stream record with tokens, effects, narrative

Usage Examples

Action DM Resolution

from worldseed.engine.dm_resolver import resolve_dm

await resolve_dm(
    action=action,
    dm_config=action_config.dm,
    ctx=ctx,
    tick=1,
    dm_provider=dm_provider,
    dm_builder=dm_builder,
    store=store,
    event_log=event_log,
    recorder=recorder,
    inbox_manager=inbox_manager,
)

Validate DM Effects

from worldseed.engine.dm_resolver import validate_dm_effects, sanitize_dm_effects

valid, reason = validate_dm_effects(response.effects, dm_config, store)
if valid:
    sanitize_dm_effects(response.effects)
    # Effects are safe to apply
else:
    print(f"Rejected: {reason}")

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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