This document describes the new sentiment tracking system implemented in mod-ollama-chat, which allows bots to develop persistent relationships with players based on their interactions.
The sentiment tracking system enables bots to remember how players treat them over time and adjust their behavior accordingly. Bots become more friendly toward players who are nice to them, and more hostile toward players who are rude or aggressive.
- Each bot-player relationship has a sentiment value between 0.0 and 1.0
- 0.0 = Extremely hostile/negative relationship
- 0.5 = Neutral relationship (default for new interactions)
- 1.0 = Extremely friendly/positive relationship
- When a player sends a message to a bot, the system analyzes the message sentiment using the LLM
- The LLM classifies the message as POSITIVE, NEGATIVE, or NEUTRAL
- The bot's sentiment toward that player is adjusted accordingly:
- POSITIVE messages increase sentiment by the configured adjustment strength
- NEGATIVE messages decrease sentiment by the configured adjustment strength
- NEUTRAL messages cause no change
Sentiment analysis is an LLM round trip, so it never runs inline.
UpdateBotPlayerSentiment() queues the work on the dispatcher and returns
immediately; ApplySentimentAnalysis() performs the call on a worker thread.
This matters because sentiment touches only the mutex-guarded in-memory map and async database writes — it needs no world-thread access, and it must never take any, since a blocking HTTP call on the world thread would stall the server.
Sentiment requests are also capped at half the dispatcher queue depth, so they can never crowd out actual chat.
Under OllamaChat.ThinkMode = auto, sentiment is the one request kind that
does use think mode when the model supports it: it is a judgement call rather
than a one-liner, and the result is never shown to players.
- Sentiment information is automatically included in bot prompts
- Bots receive context like: "Your relationship sentiment with PlayerName is 0.8 (0.0=hostile, 0.5=neutral, 1.0=friendly). Use this to guide your tone and response."
- This allows bots to respond with appropriate warmth, coldness, or neutrality based on history
The system creates a new table: mod_ollama_chat_bot_player_sentiments
CREATE TABLE IF NOT EXISTS mod_ollama_chat_bot_player_sentiments (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
bot_guid BIGINT UNSIGNED NOT NULL,
player_guid BIGINT UNSIGNED NOT NULL,
sentiment_value FLOAT NOT NULL DEFAULT 0.5,
last_updated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY unique_sentiment (bot_guid, player_guid)
);Add these settings to your mod_ollama_chat.conf file:
# Enable sentiment tracking (default: 1)
OllamaChat.EnableSentimentTracking = 1
# Default sentiment for new relationships (default: 0.5)
OllamaChat.SentimentDefaultValue = 0.5
# How much to adjust sentiment per message (default: 0.1)
OllamaChat.SentimentAdjustmentStrength = 0.1
# How often to save sentiment data in minutes (default: 10)
OllamaChat.SentimentSaveInterval = 10
# Prompt for sentiment analysis
OllamaChat.SentimentAnalysisPrompt = "Analyze the sentiment of this message: \"{message}\". Respond only with: POSITIVE, NEGATIVE, or NEUTRAL."
# Template for including sentiment in bot prompts
OllamaChat.SentimentPromptTemplate = "Your relationship sentiment with {player_name} is {sentiment_value} (0.0=hostile, 0.5=neutral, 1.0=friendly). Use this to guide your tone and response."Make sure your chat and event prompt templates include the {sentiment_info} placeholder:
# Example chat template with sentiment
OllamaChat.ChatPromptTemplate = "You are {bot_name}, a {bot_class} bot. {bot_personality} {sentiment_info} Player {player_name} says: {player_message}"
# Example event template with sentiment
OllamaChat.EventChatterPromptTemplate = "You are {bot_name}, a {bot_class} bot. {bot_personality} {sentiment_info} React to this event: {event_type} involving {actor_name}"The system provides several admin commands for managing sentiment data:
.ollama sentiment view [botname] [playername]
- No arguments: Shows all sentiment data
- Bot name only: Shows all sentiments for that bot
- Player name only: Shows all sentiments involving that player
- Both names: Shows specific bot-player sentiment
.ollama sentiment set <botname> <playername> <value>
- Manually sets sentiment between a bot and player
- Value must be between 0.0 and 1.0
.ollama sentiment reset [botname] [playername]
- No arguments: Resets ALL sentiment data
- Bot name only: Resets all sentiments for that bot
- Player name only: Resets all sentiments involving that player
- Both names: Resets specific bot-player sentiment to default
- Sentiment data is cached in memory for fast access
- Data is periodically saved to database (configurable interval)
- Memory usage scales with number of unique bot-player interactions
- Each player message triggers an additional LLM call for sentiment analysis
- Consider your LLM server capacity when enabling this feature
- Sentiment analysis uses a simple prompt and expects short responses
- Sentiment data is batched and saved periodically
- Uses REPLACE INTO for efficient upserts
- Minimal database impact with reasonable save intervals
-
First Interaction: Player "Alice" says "Hello there!" to bot "BotTank"
- No existing sentiment → starts at 0.5 (neutral)
- Message analyzed as POSITIVE
- Sentiment increases to 0.6
- Bot responds neutrally/positively
-
Positive Interaction: Alice says "You're the best tank ever!"
- Current sentiment: 0.6
- Message analyzed as POSITIVE
- Sentiment increases to 0.7
- Bot responds more warmly
-
Negative Interaction: Alice says "You suck at tanking!"
- Current sentiment: 0.7
- Message analyzed as NEGATIVE
- Sentiment decreases to 0.6
- Bot response becomes cooler
High Sentiment (0.8+):
- "Hey Alice, great to see you again!"
- "Always happy to help you out!"
- Enthusiastic, helpful tone
Neutral Sentiment (0.4-0.6):
- "Hello Alice."
- "Sure, I can help with that."
- Polite but not enthusiastic
Low Sentiment (0.2-):
- "What do you want?"
- "I suppose I could help..."
- Cold, reluctant tone
- Check that
OllamaChat.EnableSentimentTracking = 1 - Verify your LLM is responding correctly to sentiment analysis prompts
- Check server logs for sentiment analysis debug messages
- Ensure your chat templates include
{sentiment_info}placeholder
- Increase
OllamaChat.SentimentSaveIntervalto reduce database writes - Consider reducing
OllamaChat.SentimentAdjustmentStrengthfor fewer LLM calls - Monitor your LLM server load
- Ensure the sentiment table was created properly
- Check database permissions for the characters database
- Verify database connection in server logs
mod-ollama-chat_sentiment.h- Sentiment system headermod-ollama-chat_sentiment.cpp- Sentiment system implementationmod-ollama-chat_config.h- Added sentiment configuration variablesmod-ollama-chat_config.cpp- Added sentiment config loadingmod-ollama-chat_handler.cpp- Integrated sentiment into chat processingmod-ollama-chat_events.cpp- Integrated sentiment into event systemmod-ollama-chat_command.h/.cpp- Added sentiment admin commandsmod-ollama-chat_random.cpp- Added sentiment periodic saving2025_07_25_sentiment_tracking.sql- Database schema
- All sentiment data access is protected by mutex locks
- Sentiment analysis runs in background threads
- Database operations are batched for efficiency
- Chat Handler: Sentiment analysis and updates happen during chat processing
- Event System: Event prompts include sentiment context when actor is a player
- Prompt Generation: All bot prompts automatically include sentiment information
- Periodic Saves: Sentiment data is saved alongside conversation history
This system provides a persistent, evolving relationship dynamic that makes bot interactions feel more personal and reactive to player behavior over time.