Skip to content

02: RPG NPC Memory

Overview

Simulates an RPG game where NPCs build their memory of player characters through multiple interactions. Each encounter adds or updates information about the player, demonstrating incremental profile building.

Theme

Character Profile Building

Strategy

MERGE_FIELD (incremental field updates)

Key Features

  • ✅ Multiple interaction types (trade, combat, dialogue)
  • ✅ Field-level merging for profile completeness
  • ✅ Progressive reputation and relationship tracking
  • ✅ Incremental skill and achievement recognition
  • ✅ Location-based memory tracking

Data Structure

NPCMemory

player_id: str                     # Player unique ID
player_name: str | None            # Known player names
titles_earned: list[str]           # Achievements
reputation_events: list[str]       # Important events
known_skills: list[str]            # Discovered skills
trade_history: list[dict]          # Transaction history
first_meeting_location: str | None # First encounter place
last_known_location: str | None    # Last seen location
npc_opinion: str | None            # NPC's opinion of player
party_relationship: str | None     # Relationship status

Use Case

Game Development: Building NPC memory systems that track player interactions, remember past events, and evolve relationships based on accumulated experiences.

Benefits: - Realistic NPC memory of player interactions - Dynamic relationship tracking - Progressive skill discovery - Persistent reputation system

Running the Example

cd examples/
python 02_rpg_npc_memory.py

Output

Results are stored in temp/npc_memory/: - memory.json: NPC memory records for each player - metadata.json: Schema and statistics

What You'll Learn

  1. Incremental Updates: How to progressively build profiles through multiple interactions
  2. Field-Level Merging: Merging individual fields while preserving list information
  3. Relationship Tracking: Maintaining evolving relationships and reputation
  4. Game State Integration: Integrating OntoMem with game systems

No API Required ✅

This example works without any external API keys or dependencies beyond the core OntoMem package.

Next Examples