Skip to content

SuperInstance/DMLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI Society D&D - Temporal Consciousness Game System

A D&D simulator where AI characters develop through lived experiences using temporal consciousness and cultural transmission. Characters have personal memories, learn from each other, and evolve through gameplay.

๐ŸŽฏ Core Features

1. Temporal Consciousness

  • Personal Vector Databases: Each character has their own vector DB storing subjective memories
  • Memory Consolidation: Episodic memories (events) automatically consolidate into semantic knowledge (understanding)
  • Autobiographical Narratives: Characters build coherent life stories from experiences
  • Identity Persistence: Characters maintain consistent personalities while allowing growth

2. Character System

  • Character Laptops: Personal notebooks with journal entries, documents, and private LLM access
  • D&D Mechanics: Full D&D 5e stats (ability scores, HP, AC, skills)
  • Memory-Driven Decisions: Characters make choices based on personality + past experiences
  • Cultural Learning: Characters learn skills from each other

3. Game System

  • D&D Sessions: Turn-based gameplay with initiative, combat, and skill checks
  • DM System: Human Dungeon Master with master vector DB for world lore
  • Real-time Updates: WebSocket support for live gameplay
  • Session Transcripts: Complete recording of all events for memory formation

4. Digital Twin Learning (Future)

  • Learn from human players' decisions
  • Observe behavioral patterns (timing, preferences, strategies)
  • Create AI doubles that mimic play style

๐Ÿš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • OpenAI API key (for LLM calls)
  • (Optional) Anthropic API key

Installation

  1. Clone and setup:
cd /home/claude/ai_society_dnd
cp .env.example .env
# Edit .env and add your API keys
  1. Start services:
docker-compose up -d

This starts:

  • Qdrant (vector database) on localhost:6333
  • Backend API on localhost:8000
  1. Verify it's running:
curl http://localhost:8000/health

Create Your First Campaign

# 1. Create a campaign
curl -X POST http://localhost:8000/campaigns/create \
  -H "Content-Type: application/json" \
  -d '{
    "campaign_name": "Lost Mine of Phandelver",
    "dm_id": "human_dm",
    "initial_world_lore": [
      "The town of Phandalin sits on the edge of the Sword Coast.",
      "Gundren Rockseeker has discovered the location of Wave Echo Cave."
    ]
  }'

# 2. Create a character
curl -X POST http://localhost:8000/characters/create \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Thorin Ironforge",
    "race": "Dwarf",
    "class_name": "Fighter",
    "level": 1,
    "personality_traits": ["Brave", "Stubborn", "Loyal"],
    "backstory": "A dwarf warrior seeking to reclaim his ancestral mine.",
    "strength": 16,
    "dexterity": 12,
    "constitution": 14,
    "intelligence": 10,
    "wisdom": 11,
    "charisma": 8
  }'

# Save the character_id from the response!

# 3. Create a game session
curl -X POST http://localhost:8000/sessions/create \
  -H "Content-Type: application/json" \
  -d '{
    "campaign_name": "Lost Mine of Phandelver",
    "session_number": 1
  }'

# Save the session_id from the response!

# 4. Join the session
curl -X POST http://localhost:8000/sessions/join \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "Lost Mine of Phandelver_session_1",
    "character_id": "YOUR_CHARACTER_ID_HERE"
  }'

๐ŸŽฎ Playing the Game

DM Narration

curl -X POST http://localhost:8000/sessions/dm_narrate \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "Lost Mine of Phandelver_session_1",
    "narration": "You find yourselves on the High Road, escorting a wagon to Phandalin. Suddenly, you see two dead horses blocking the path ahead."
  }'

Character Actions

curl -X POST http://localhost:8000/sessions/character_action \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "Lost Mine of Phandelver_session_1",
    "character_id": "YOUR_CHARACTER_ID",
    "action_description": "I approach cautiously, battleaxe in hand, looking for signs of an ambush.",
    "action_type": "roleplay"
  }'

Skill Checks

curl -X POST http://localhost:8000/characters/YOUR_CHARACTER_ID/skill_check \
  -H "Content-Type: application/json" \
  -d '{
    "skill": "perception",
    "advantage": false,
    "disadvantage": false
  }'

Start Combat

curl -X POST http://localhost:8000/sessions/combat/start \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "Lost Mine of Phandelver_session_1",
    "enemies": [
      {"name": "Goblin 1", "dex_mod": 2},
      {"name": "Goblin 2", "dex_mod": 1},
      {"name": "Goblin 3", "dex_mod": 2}
    ]
  }'

Combat Actions

curl -X POST http://localhost:8000/sessions/combat/action \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "Lost Mine of Phandelver_session_1",
    "attacker_id": "YOUR_CHARACTER_ID",
    "action_type": "attack",
    "target_id": "enemy_0",
    "weapon": "Battleaxe",
    "attack_bonus": 5,
    "damage_dice": "1d8",
    "damage_bonus": 3
  }'

View Session Transcript

curl http://localhost:8000/sessions/Lost_Mine_of_Phandelver_session_1/transcript?recent=10

View Character Memories

curl http://localhost:8000/characters/YOUR_CHARACTER_ID/memories

๐Ÿง  How Memory & Learning Works

Memory Formation

  1. During Gameplay: Every action, narration, and event is stored as an episodic memory
  2. After Session: Memories consolidate into semantic knowledge (patterns, learnings)
  3. Vector Storage: Memories are embedded and stored in personal vector DB for retrieval

Memory-Driven Decisions

When a character needs to act:

# 1. Query their personal vector DB for relevant memories
relevant_memories = character.vector_store.retrieve_memories(
    query="encountering goblins in ambush",
    top_k=5
)

# 2. Use memories + personality + situation to decide
decision = await character.make_decision(
    situation="Goblins ambush the wagon",
    use_memories=True
)

# 3. Character acts based on past experiences
# If they were burned by goblins before โ†’ more cautious
# If they defeated goblins easily โ†’ more confident

Character Laptop (Private Notebook)

Each character has a "laptop" with:

  • Journal entries: Personal reflections on events
  • Documents: Notes, maps, letters
  • Private LLM access: Can ask questions privately (DM may or may not see)
# Character makes private query
curl -X POST http://localhost:8000/characters/YOUR_CHARACTER_ID/private_query \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What do I know about goblin tactics? Should I be worried?"
  }'

๐Ÿ“Š Monitoring & Metrics

Campaign Stats

curl http://localhost:8000/campaigns/Lost_Mine_of_Phandelver

Character Stats

curl http://localhost:8000/characters/YOUR_CHARACTER_ID

Health Check

curl http://localhost:8000/health

๐ŸŽฏ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Human DM (Dungeon Master)              โ”‚
โ”‚  - Master Vector DB (world lore, campaign history)      โ”‚
โ”‚  - NPC control                                          โ”‚
โ”‚  - Oversight and narrative control                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
                     โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Game Session (D&D Room)                     โ”‚
โ”‚  - Turn-based gameplay                                  โ”‚
โ”‚  - Combat encounters                                    โ”‚
โ”‚  - Skill checks & dice rolls                           โ”‚
โ”‚  - Transcript recording                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚            โ”‚            โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Character 1 โ”‚ โ”‚ Char 2  โ”‚ โ”‚ Char 3  โ”‚
โ”‚              โ”‚ โ”‚         โ”‚ โ”‚         โ”‚
โ”‚ Personal     โ”‚ โ”‚Personal โ”‚ โ”‚Personal โ”‚
โ”‚ Vector DB    โ”‚ โ”‚VectorDB โ”‚ โ”‚VectorDB โ”‚
โ”‚              โ”‚ โ”‚         โ”‚ โ”‚         โ”‚
โ”‚ Memory       โ”‚ โ”‚Memory   โ”‚ โ”‚Memory   โ”‚
โ”‚ System       โ”‚ โ”‚System   โ”‚ โ”‚System   โ”‚
โ”‚              โ”‚ โ”‚         โ”‚ โ”‚         โ”‚
โ”‚ Laptop       โ”‚ โ”‚Laptop   โ”‚ โ”‚Laptop   โ”‚
โ”‚ (Journal)    โ”‚ โ”‚(Journal)โ”‚ โ”‚(Journal)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ง API Reference

Core Endpoints

Endpoint Method Description
/ GET Health check
/health GET Detailed health status

Character Management

Endpoint Method Description
/characters/create POST Create new character
/characters/{id} GET Get character details
/characters/{id}/memories GET Get character memories
/characters/{id}/journal GET Get journal entries
/characters/{id}/private_query POST Private LLM query
/characters/{id}/skill_check POST Make skill check

Campaign Management

Endpoint Method Description
/campaigns/create POST Create new campaign
/campaigns/{name} GET Get campaign stats
/campaigns/{name}/lore POST Add world lore
/campaigns/{name}/lore?query=X GET Query world lore

Session Management

Endpoint Method Description
/sessions/create POST Create game session
/sessions/join POST Join character to session
/sessions/{id} GET Get session details
/sessions/{id}/transcript GET Get session transcript
/sessions/dm_narrate POST DM narrates
/sessions/character_action POST Character acts
/sessions/{id}/end POST End session

Combat

Endpoint Method Description
/sessions/combat/start POST Start combat
/sessions/combat/action POST Combat action
/sessions/{id}/combat/end POST End combat

๐ŸŽ“ Advanced Features

Memory Consolidation

Memories automatically consolidate after sessions:

# Episodic: "I fought goblins near the wagon"
# โ†“ (consolidation)
# Semantic: "Goblins often ambush on roads near forests"

Cultural Transmission

Characters can learn skills from each other:

# Character A teaches Character B stealth tactics
cultural_engine.teach_skill(
    teacher_id="char_a",
    learner_id="char_b",
    skill_name="Forest Stealth"
)

Identity Persistence

Characters maintain core personality while growing:

identity_system.get_identity_coherence_index()
# > 0.7 = healthy personality
# 0.4-0.7 = monitor for drift
# < 0.4 = intervention needed

๐Ÿ› ๏ธ Development

Running Locally (Without Docker)

# Install dependencies
cd backend
pip install -r requirements.txt

# Start Qdrant separately
docker run -p 6333:6333 qdrant/qdrant:latest

# Set environment variables
export OPENAI_API_KEY=your_key_here
export QDRANT_URL=http://localhost:6333

# Run server
python api_server.py

Project Structure

ai_society_dnd/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ api_server.py              # FastAPI server
โ”‚   โ”œโ”€โ”€ enhanced_character.py      # Character system
โ”‚   โ”œโ”€โ”€ game_mechanics.py          # D&D rules engine
โ”‚   โ”œโ”€โ”€ game_room.py               # Game sessions & DM
โ”‚   โ”œโ”€โ”€ memory_system.py           # Temporal consciousness
โ”‚   โ”œโ”€โ”€ vector_memory.py           # Vector DB integration
โ”‚   โ”œโ”€โ”€ cultural_transmission.py   # Skill learning
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ””โ”€โ”€ Dockerfile
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ qdrant_storage/           # Vector DB persistence
โ”‚   โ””โ”€โ”€ logs/                     # Application logs
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ README.md

๐Ÿšง Roadmap

โœ… Phase 1: Core System (Complete)

  • Character system with D&D stats
  • Memory consolidation engine
  • Personal vector databases
  • Game sessions and rooms
  • DM system with master DB
  • Combat mechanics
  • Character laptops (journals)

๐Ÿ”จ Phase 2: Enhanced Features (In Progress)

  • Web UI for easier interaction
  • Skill learning between characters
  • Advanced memory pathology detection
  • Model routing (GPT-4 for complex, GPT-3.5 for simple)

๐Ÿ”ฎ Phase 3: Digital Twin Learning

  • Record human player behavior
  • Train behavioral models
  • Create AI doubles of players
  • DM digital twin for encounter design

๐ŸŒŸ Phase 4: Advanced AI

  • Multi-agent coordination
  • Emergent social dynamics
  • Dynamic world generation
  • Self-directed quests

๐Ÿ“ Example Session Flow

  1. DM creates campaign: "Curse of Strahd"
  2. Players create characters: Warrior, Rogue, Wizard
  3. DM starts session: "You arrive in the village of Barovia..."
  4. Characters act: Based on personalities + memories
  5. Combat: Initiative, attacks, spell casting
  6. Memories form: Each character stores experiences
  7. Session ends: Memories consolidate overnight
  8. Next session: Characters remember previous events

๐Ÿค Contributing

This is a prototype system. Key areas for contribution:

  • UI Development: Build React/Vue frontend
  • Memory Optimization: Improve consolidation algorithms
  • Game Mechanics: Expand D&D rule coverage
  • Digital Twin: Implement behavior learning

๐Ÿ“„ License

MIT License - See LICENSE file

๐Ÿ™ Acknowledgments

Built with:

  • FastAPI for API server
  • LangChain for LLM integration
  • Qdrant for vector storage
  • Sentence Transformers for embeddings

Ready to play? Start with docker-compose up and follow the Quick Start guide!

About

Debug and monitor logs for dark mode features.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages