DiceTales

Enhanced Human-Like AI System for DiceTales

Overview

DiceTales features an advanced AI system that provides human-like conversations with comprehensive memory and plot grounding. The system uses modern conversational models from Hugging Face to deliver immersive, consistent storytelling experiences with full campaign continuity.

Key Features

πŸ€– Human-Like Conversational Models

Primary Models (in order of preference):

  1. microsoft/GODEL-v1_1-large-seq2seq - Advanced conversational AI with superior context understanding
  2. facebook/blenderbot-400M-distill - Optimized for natural dialogue generation
  3. microsoft/GODEL-v1_1-base-seq2seq - Balanced quality and performance
  4. facebook/blenderbot-1B-distill - Large-scale conversational model

Fallback Models:

πŸ’­ Enhanced Conversation Management

Dynamic Context Building:

Response Enhancement:

🧠 Advanced Memory System Integration

Comprehensive Memory Context:

Character Consistency:

βš™οΈ Configuration Settings

Conversation Parameters:

CONVERSATION_SETTINGS: {
    maxContextLength: 2048,      // Maximum context window
    temperature: 0.8,            // Creative response balance
    topP: 0.9,                   // Quality nucleus sampling
    repetitionPenalty: 1.1,      // Reduce repetitive responses
    maxNewTokens: 150,           // Response length limit
    doSample: true,              // Enable response variety
    numBeams: 3                  // Beam search for quality
}

Memory Configuration:

MEMORY_SETTINGS: {
    maxConversationHistory: 20,   // Conversation exchanges to remember
    plotContextWindow: 5,         // Plot-relevant events to track
    characterMemoryDepth: 10      // Character interaction history
}

Enhanced AI Manager Class

The AIManager class provides comprehensive storytelling capabilities:

Memory Manager Integration

The MemoryManager provides AI with:

Usage Examples

Basic Campaign Start

// Initialize the enhanced AI system
const aiManager = new AIManager();
await aiManager.initialize();

// Start a new campaign with memory integration
await aiManager.startCampaign();

Processing Player Actions

// Process an action with full context integration
await aiManager.processPlayerAction({
    action: "Approach the mysterious stranger carefully",
    type: "social"
});

Memory Context Building

// Build comprehensive memory context for AI
const character = gameState.getCharacter();
const campaign = gameState.getCampaign();
const memoryContext = aiManager.buildMemoryContext(character, campaign);

Technical Implementation

AI Context Structure

The AI receives comprehensive context including:

🎭 CHARACTER PROFILE: [Name, Class, Level, Background, Current Status]
πŸ“Š ABILITY SCORES: [STR, DEX, CON, INT, WIS, CHA with current values]
❀️ HEALTH STATUS: [Current/Max HP, conditions, injuries]
πŸŽ’ INVENTORY: [Equipped items, carried equipment, special items]
🧠 RECENT DECISIONS: [Last 3 significant choices and consequences]
πŸ‘₯ KEY RELATIONSHIPS: [Important NPCs and relationship status]
πŸ” DISCOVERIES: [Recent findings and their significance]
🎯 SKILLS USED: [Frequently used skills and success patterns]
πŸ“– ACTIVE PLOTS: [Current story threads and objectives]
πŸ—ΊοΈ LOCATION CONTEXT: [Current area and relevant locations]

Response Processing Pipeline

  1. Context Assembly: Builds comprehensive prompt with character and memory data
  2. API Request: Sends request to HuggingFace models with fallback handling
  3. Response Enhancement: Cleans and enhances raw AI output for immersion
  4. Memory Extraction: Automatically extracts important information for storage
  5. Display Processing: Formats response for game interface display

// Send a message with full context const response = await aiManager.generateStoryContent( β€œI want to explore the mysterious tavern”, { useEnhancedContext: true, conversational: true } );


### Plot-Grounded Interaction
```javascript
// Add plot context through memory manager
aiManager.memoryManager.recordDecision('Helped the village elder', 'Gained villagers trust');
aiManager.memoryManager.updatePlotThread('Village Quest', 'active', 'Find the missing artifact');

// Generate response with plot awareness
const response = await aiManager.generateStoryContent(
    "What should I do next?",
    { plotGrounded: true }
);

Testing and Validation

Test Interface

Use test-enhanced-ai.html to validate the system:

  1. AI System Initialization: Verify enhanced models load correctly
  2. Interactive Conversation: Test human-like dialogue generation
  3. Memory Integration: Validate plot grounding and consistency
  4. Performance Monitoring: Track response times and quality metrics

Key Test Scenarios

  1. Conversation Continuity: Verify responses reference previous exchanges
  2. Plot Consistency: Ensure responses align with stored plot threads
  3. Character Memory: Confirm NPC interactions are remembered
  4. Response Quality: Validate human-like, engaging responses

Benefits Over Previous System

Improved Conversation Quality

Better Plot Management

Enhanced User Experience

Configuration for Optimal Performance

API Key Setup (Optional)

For improved rate limits and performance, set up a Hugging Face API key:

window.HUGGINGFACE_API_KEY = 'your_api_key_here';

Model Selection

The system automatically selects the best available model, but you can customize the preference order in config.js:

HUGGINGFACE_MODELS: [
    'your_preferred_model',
    'microsoft/GODEL-v1_1-large-seq2seq',
    // ... other models
]

Memory Tuning

Adjust memory settings based on your use case:

Troubleshooting

Common Issues

  1. Model Loading Failures: System automatically falls back to alternative models
  2. Slow Responses: Check network connection; system tries multiple models
  3. Repetitive Responses: Memory system should prevent this; check memory integration
  4. Inconsistent Plot: Verify MemoryManager is properly recording plot elements

Performance Optimization

  1. Response Time: Primary models (GODEL, BlenderBot) offer best quality-speed balance
  2. Context Length: Adjust maxContextLength based on available resources
  3. Memory Usage: Tune memory settings to balance consistency and performance

Future Enhancements

Potential improvements for the AI system:

  1. Fine-tuned Models: Custom models trained on D&D/RPG content
  2. Emotion Tracking: AI responses based on character emotional state
  3. Multi-Character Voices: Different AI personalities for different NPCs
  4. Advanced Plot Generation: AI-driven story arc development
  5. Real-time Learning: System adaptation based on player preferences

Conclusion

The enhanced AI system transforms DiceTales from a basic storytelling tool into a sophisticated, context-aware narrative companion. By combining modern conversational AI with comprehensive memory management, it delivers human-like interactions that maintain plot consistency and character development throughout the gaming experience.