Improved validation based on story

This commit is contained in:
Dejvino
2026-06-30 22:32:56 +02:00
parent e97db7f5b7
commit 5862254255
3 changed files with 23 additions and 9 deletions
+14 -2
View File
@@ -8,7 +8,7 @@ from .paths import CHAR_PATH, WORLD_PATH
from . import state
VALIDATION_PROMPT = """You are a strict RPG game master validating whether a player's action is possible given the game state. Be thorough — check inventory, stats, location, NPCs, and story logic.
VALIDATION_PROMPT = """You are a strict RPG game master validating whether a player's action is possible given the game state. Be thorough — check inventory, stats, location, NPCs, story context, and story logic.
## Character
{character}
@@ -16,6 +16,12 @@ VALIDATION_PROMPT = """You are a strict RPG game master validating whether a pla
## World
{world}
## Session Log
{log}
## Recent Story
{story}
## Player Action
{action}
@@ -24,6 +30,7 @@ VALIDATION_PROMPT = """You are a strict RPG game master validating whether a pla
- Are they asserting something that contradicts the state? -> invalid
- Is the action nonsensical given the situation? -> invalid
- Does the action make sense given the character's abilities and resources? -> valid
- Pay close attention to the Recent Story section — entities like monsters, NPCs, and hazards currently present in the scene ARE valid targets for action.
- If valid, also check: if they're using a consumable item, note that it must be removed from inventory.
Reply with ONLY the JSON object. Examples:
@@ -39,6 +46,9 @@ or
def validate_action(
player_action: str,
*,
story: str = "",
log: str = "",
on_debug: callable = None,
) -> tuple[bool, str]:
"""Ask the LLM whether a player action is valid given the game state. Returns (valid, reason)."""
@@ -47,8 +57,10 @@ def validate_action(
char = state.read_file(CHAR_PATH) or "*No character sheet.*"
world = state.truncate_world(state.read_file(WORLD_PATH) or "") or "*No world state.*"
recent = story.strip() or state.read_recent_book() or "*No prior story.*"
log_entries = log.strip() or state.read_recent_log() or "*No recent events.*"
prompt = VALIDATION_PROMPT.format(character=char, world=world, action=player_action)
prompt = VALIDATION_PROMPT.format(character=char, world=world, log=log_entries, story=recent, action=player_action)
text = call_llm(
[{"role": "user", "content": prompt}],