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):
microsoft/GODEL-v1_1-large-seq2seq
- Advanced conversational AI with superior context understanding
facebook/blenderbot-400M-distill
- Optimized for natural dialogue generation
microsoft/GODEL-v1_1-base-seq2seq
- Balanced quality and performance
facebook/blenderbot-1B-distill
- Large-scale conversational model
Fallback Models:
microsoft/DialoGPT-large
- Proven conversational model
microsoft/DialoGPT-medium
- Medium-sized reliable model
gpt2-large
/ distilgpt2
- General purpose language models
π Enhanced Conversation Management
Dynamic Context Building:
- Integrates character stats, equipment, and current health
- References past decisions and their consequences
- Maintains awareness of NPC relationships and interactions
- Incorporates discovered locations and world state
- Uses active plot threads for story continuity
Response Enhancement:
- Removes AI artifacts and meta-commentary
- Adds natural variations to prevent repetition
- Enhances descriptive language for immersion
- Maintains proper grammar and sentence structure
- Contextualizes responses to character background and class
π§ Advanced Memory System Integration
Comprehensive Memory Context:
- Tracks recent player decisions with consequences
- Monitors active plot threads and quest progression
- Remembers important character relationships and their history
- Records significant discoveries and their impact
- Maintains detailed location descriptions for consistency
Character Consistency:
- Integrates character class abilities and background
- Tracks skill usage patterns and development
- Remembers character personality traits and choices
- References equipment and inventory appropriately
- Maintains continuity across gaming sessions
βοΈ 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:
- Contextual Prompt Building: Integrates character data, campaign history, and memory context
- Response Quality Enhancement: Post-processes AI responses for better human-like quality
- Memory Integration: Works seamlessly with MemoryManager for plot consistency
- Model Fallback System: Automatically tries multiple models for reliability
- Campaign Continuity: Maintains story consistency across sessions
- Character Integration: Uses character class, background, and abilities appropriately
Memory Manager Integration
The MemoryManager
provides AI with:
- Comprehensive Context: Recent decisions, relationships, discoveries, and plot threads
- Character Development: Skill usage patterns and growth moments
- World Consistency: Location descriptions and world state changes
- Relationship Tracking: NPC interactions and relationship progression
- Plot Continuity: Active storylines and their current status
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
- Context Assembly: Builds comprehensive prompt with character and memory data
- API Request: Sends request to HuggingFace models with fallback handling
- Response Enhancement: Cleans and enhances raw AI output for immersion
- Memory Extraction: Automatically extracts important information for storage
- 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:
- AI System Initialization: Verify enhanced models load correctly
- Interactive Conversation: Test human-like dialogue generation
- Memory Integration: Validate plot grounding and consistency
- Performance Monitoring: Track response times and quality metrics
Key Test Scenarios
- Conversation Continuity: Verify responses reference previous exchanges
- Plot Consistency: Ensure responses align with stored plot threads
- Character Memory: Confirm NPC interactions are remembered
- Response Quality: Validate human-like, engaging responses
Benefits Over Previous System
Improved Conversation Quality
- More Natural: Uses modern conversational models instead of basic GPT-2
- Context Aware: Maintains conversation history and plot state
- Consistent: Integrates with memory system for narrative continuity
- Engaging: Enhanced response quality with descriptive language
Better Plot Management
- Grounded Responses: All responses consider active plot threads
- Character Development: Tracks and references character growth
- Relationship Awareness: Remembers past NPC interactions
- Decision Consequences: Maintains awareness of player choices
Enhanced User Experience
- Immersive Storytelling: More engaging and consistent narrative
- Reduced Repetition: Intelligent variation in response patterns
- Better Flow: Natural conversation transitions and continuity
- Reliable Performance: Robust fallback system ensures availability
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:
- Increase
maxConversationHistory
for longer narrative consistency
- Adjust
plotContextWindow
for more/less plot grounding
- Modify
characterMemoryDepth
for character interaction tracking
Troubleshooting
Common Issues
- Model Loading Failures: System automatically falls back to alternative models
- Slow Responses: Check network connection; system tries multiple models
- Repetitive Responses: Memory system should prevent this; check memory integration
- Inconsistent Plot: Verify MemoryManager is properly recording plot elements
- Response Time: Primary models (GODEL, BlenderBot) offer best quality-speed balance
- Context Length: Adjust
maxContextLength
based on available resources
- Memory Usage: Tune memory settings to balance consistency and performance
Future Enhancements
Potential improvements for the AI system:
- Fine-tuned Models: Custom models trained on D&D/RPG content
- Emotion Tracking: AI responses based on character emotional state
- Multi-Character Voices: Different AI personalities for different NPCs
- Advanced Plot Generation: AI-driven story arc development
- 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.