Reggie Context v2.1 Updates
Improvements to personalized intros, turn counting, and context injection.
Overview
Context v2.1 addresses issues discovered in v2.0 production use, particularly around:
- Personalized intro triggering on every turn (fixed)
- Turn counting reliability (now server-side)
- Intro prompt quality (more natural, less generic)
Issue 1: Personalized Intro on Every Message
Problem
The personalized "welcome back" intro was appearing on every message, not just the first turn of a conversation. Users saw greetings like "Good to see you again, Brett!" repeatedly.
Root Cause
Turn number was calculated from the conversation array sent by the frontend:
const turnNumber = conversation.filter((m) => (m.role || 'user') === 'user').length;
But the frontend only sends the current message, not the full history:
messages: [{ role: 'user', content: prompt }] // Always 1 message
This meant turnNumber was always 1.
Fix
Now queries the session's actual message count from the database:
// In prepareContext()
let actualTurnNumber = turnNumber;
if (sessionId) {
const { rows } = await config.pool.query(
`SELECT COALESCE((metadata->>'message_count')::int, 0) as msg_count
FROM admin.chat_sessions WHERE id = $1 AND user_id = $2`,
[sessionId, userId]
);
if (rows.length > 0) {
actualTurnNumber = rows[0].msg_count === 0 ? 1 : rows[0].msg_count + 1;
}
}
The message_count is incremented server-side in recordMessage(), so it's always accurate.
Issue 2: Generic Intro Messages
Problem
Personalized intros were too generic and felt forced:
- "Welcome back! Good to see you again."
- "I remember we discussed Python, SQL, and various integrations..."
Fix
Rewrote the intro prompt to be more natural and context-aware:
Before:
Generate a SHORT (2-3 sentences max) personalized greeting that:
1. Warmly acknowledges the user by first name
2. References something specific from their recent conversations
3. Shows you remember them without being creepy
4. Naturally transitions to helping with their current request
After:
Generate a context-aware opener for the AI assistant "Reggie". Return ONLY the opener text.
RULES:
- MAX 1-2 sentences
- ONLY reference past context if it's DIRECTLY relevant to currentQuery
- If no clear relevance, return JUST: "Hey {userName}!" (nothing more)
- Never say "welcome back" or "good to see you" - too generic
- Never list topics or summarize history unprompted
WHEN TO USE CONTEXT (do this):
- currentQuery continues a recent topic → reference it specifically
- currentQuery relates to a known interest → acknowledge briefly
- User left mid-task last session → offer to resume
WHEN TO SKIP CONTEXT (just greet):
- currentQuery is a new/unrelated topic
- No clear connection to history
- Generic questions like "hi" or "help me with..."
Also reduced:
max_tokens: 150 → 80temperature: 0.7 → 0.5
Result
- New topic: "Hey Brett!"
- Related topic: "Hey Brett, picking up from your Deputy API work?"
- Resuming: "Hey Brett, still working on that roster extraction?"
Console Logging
Added detailed logging for context operations:
Personalized Intro Generation
[CONTEXT] ════════════════════════════════════════════
[CONTEXT] Personalized Intro Generated for: Brett
[CONTEXT] Time since last: 2 hours ago
[CONTEXT] Interests: python, sql, api design
[CONTEXT] Query: "Help me with database migration..."
[CONTEXT] Intro: "Hey Brett!"
[CONTEXT] Latency: 203ms
[CONTEXT] ════════════════════════════════════════════
Preference Analyzer
[PREF-ANALYZER] ═══════════════════════════════════════
[PREF-ANALYZER] User: abc123 | Session: def456...
[PREF-ANALYZER] Message: "Please be more concise"
[PREF-ANALYZER] Detected: PREFERENCE
[PREF-ANALYZER] → Category: length
[PREF-ANALYZER] → Preference: concise_responses
[PREF-ANALYZER] → Confidence: 90%
[PREF-ANALYZER] Reasoning: User explicitly requested brevity
[PREF-ANALYZER] Latency: 145ms
[PREF-ANALYZER] ═══════════════════════════════════════
Files Changed
| File | Changes |
|---|---|
backend/services/chat-context.js | Session-based turn counting, improved intro prompt, logging |
backend/services/preference-analyzer.js | Added console logging for detected preferences/workflows |
Testing
To verify the fix:
- Start new conversation → Should see personalized intro (if history exists)
- Send second message → Should NOT see personalized intro
- Check server logs → Should show
actualTurnNumber> 1 for subsequent messages
Related Docs
- Reggie Chat Context Intelligence - Original v2 design
- Reggie Chat Context Extended - Extended v2 details
- Reggie Preference Learning - Preference learning system