Principle:AIScientists Dev WorldSeed DM Resolution
| Knowledge Sources | |
|---|---|
| Domains | LLM, Game_AI, State_Management |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
A judgment-resolution pipeline that delegates uncertain action outcomes to an LLM-based Dungeon Master, validates and sanitizes the returned effects through a safety layer, and applies them atomically with rollback-on-failure — bridging mechanical game rules and open-ended narrative simulation.
Description
The DM (Dungeon Master) is WorldSeed's mechanism for resolving actions whose outcomes are too complex for deterministic rules. When an action has a `dm` config field, its mechanical effects execute immediately, but the uncertain consequences are deferred to an LLM judge.
The resolution pipeline:
- Context assembly: `DMContextBuilder` gathers the full world state, recent events, target history, scene description, and DM knowledge into a `DMContext`.
- Prompt shaping: Templates build a two-part prompt: a cacheable system prompt (rules, scene, hint, allowed ops) and a per-call user message (world state + action).
- LLM call: `DMProvider.judge()` calls the LLM with structured output via Instructor/Pydantic, returning a `DMResponse` with narrative and effects.
- Validation/sanitization: `validate_dm_effects()` checks count limits, allowed operators, and entity existence. `sanitize_dm_effects()` adds safety defaults (e.g., `min:0` for decrement).
- Application: `apply_dm_response()` snapshots affected entities, executes effects, and delivers the narrative. On failure, state is rolled back.
The pipeline retries up to 2 times with error feedback sent back to the LLM on validation failure. If all attempts fail, a fallback narrative is whispered to the agent.
Usage
Use this principle when actions have uncertain outcomes that require LLM judgment. The DM is configured per-action in the scene config's `dm` field with `hint`, `allowed_ops`, `max_effects`, and `scope`.
Theoretical Basis
The DM resolution follows a structured-output-with-validation pattern:
# Abstract pipeline (NOT real implementation)
dm_ctx = dm_builder.build(action, dm_config, tick)
for attempt in range(max_attempts):
response = await dm_provider.judge(dm_ctx)
valid, reason = validate_dm_effects(response.effects, dm_config, store)
if valid:
sanitize_dm_effects(response.effects)
break
dm_ctx.error_feedback = reason # retry with feedback
apply_dm_response(response, store, ...) # atomic with rollback
The validation layer is a safety boundary: it ensures the LLM cannot execute disallowed operations, create more effects than permitted, or reference nonexistent entities. The atomic application with snapshot/rollback ensures partial failure doesn't leave the world in an inconsistent state.
Related Pages
Implemented By
- Implementation:AIScientists_Dev_WorldSeed_dm_resolver
- Implementation:AIScientists_Dev_WorldSeed_DMContextBuilder_build
- Implementation:AIScientists_Dev_WorldSeed_LiteLLMDMProvider_judge
- Implementation:AIScientists_Dev_WorldSeed_build_dm_prompt