Dialogue Systems Intermediate

The dialogue system is the heart of an AI NPC. It takes player input, combines it with the NPC's persona, world context, and conversation history, then generates a contextually appropriate response using a large language model.

Persona Design

Every NPC needs a well-crafted system prompt that defines their personality, knowledge, speech patterns, and boundaries. A good persona prompt includes:

  • Identity: Name, role, background story
  • Personality traits: Temperament, humor style, formality level
  • Knowledge scope: What they know and do not know
  • Speech patterns: Vocabulary, catchphrases, accent indicators
  • Boundaries: Topics they refuse to discuss, lore constraints

Context Window Management

LLMs have limited context windows. For long conversations, implement a sliding window strategy:

  1. System prompt (always included) — persona, world state, rules
  2. Memory summary — compressed summary of previous interactions
  3. Recent messages — last 10-20 turns of dialogue
  4. Current world state — time of day, player location, recent events

Guardrails and Content Safety

AI NPCs must stay in character and within content guidelines. Implement multiple layers of protection:

Safety Layers:
  • System prompt instructions that forbid breaking character
  • Input sanitization to filter harmful player messages
  • Output validation to catch lore-breaking or inappropriate responses
  • Fallback responses when the LLM fails or returns unsafe content

Structured Output

Request structured JSON responses from the LLM that include not just the dialogue text but also metadata: emotion tag, animation trigger, quest state changes, and relationship score adjustments. This lets the game engine react to the full context of the conversation.