Skip to main content

Reggie Preference Learning

Automatic learning of user preferences and repetitive workflows to make Reggie smarter over time.


Overview

The Preference Learning System runs a lightweight analyzer in parallel with every Reggie chat message. It detects:

  1. Preferences - How the user wants responses formatted/styled
  2. Workflows - Repetitive tasks the user does regularly
  3. Pain Points - When users re-explain or express frustration
  4. Corrections - When users explicitly correct Reggie's behavior

These are stored and automatically injected into future conversations, making Reggie progressively smarter about each user.


Architecture

┌─────────────────────────────────────────────────────────┐
│ User Message │
└─────────────────────┬───────────────────────────────────┘

┌────────────┴────────────┐
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────────────┐
│ Main LLM Call │ │ Preference Analyzer │
│ (GPT-5/Pro) │ │ (GPT-4.1-nano) │
│ │ │ - Detects preferences │
│ │ │ - Matches workflows │
│ │ │ - Logs patterns │
└────────┬────────┘ └───────────┬─────────────┘
│ │
│ ▼
│ ┌─────────────────────────┐
│ │ Store to Database │
│ │ - user_llm_preferences │
│ │ - user_learned_workflows│
│ │ - user_prompt_patterns │
│ └─────────────────────────┘


┌─────────────────────────────────────────────────────────┐
│ Response (with preferences/workflow context injected) │
└─────────────────────────────────────────────────────────┘

What Gets Learned

Preferences (Response Style)

CategoryExamples
tone"Be more casual", "No emojis", "Professional tone"
length"Be concise", "Give detailed explanations", "Bullet points only"
format"Always show code examples", "Include SQL queries", "Step-by-step"
expertise"I'm a senior dev", "Skip the basics", "Explain like I'm new"
output"Always show your reasoning", "Just give me the answer"
behavior"Don't apologize", "Ask clarifying questions first"

Workflows (Repetitive Tasks)

When the system detects a user asking similar questions 3+ times, it creates a learned workflow:

{
"workflow_name": "roster_vehicle_extraction",
"trigger_pattern": "roster CSS/file + vehicles",
"learned_steps": [
"Parse CSS table structure",
"Find vehicle column",
"Extract assignments by row",
"Format as summary list"
],
"preferred_output": "bullet list with times"
}

Next time the user drops a roster file, Reggie proactively knows what to do.


Data Model

admin.user_llm_preferences

- id UUID
- user_id UUID (FK)
- category TEXT (tone, format, length, expertise, output, behavior)
- preference TEXT (short identifier)
- description TEXT (human-readable for UI)
- source_message TEXT (what triggered this)
- confidence FLOAT (0-1)
- times_reinforced INT (increases when re-detected)
- active BOOLEAN
- created_at, updated_at

admin.user_learned_workflows

- id UUID
- user_id UUID (FK)
- workflow_name TEXT
- trigger_pattern TEXT
- learned_steps JSONB
- preferred_output TEXT
- example_input TEXT
- example_output TEXT
- times_detected INT
- last_used_at TIMESTAMPTZ
- confidence FLOAT
- active BOOLEAN
- created_at, updated_at

admin.user_prompt_patterns

- id UUID
- user_id UUID (FK)
- session_id UUID (FK)
- prompt_hash TEXT (MD5 for similarity matching)
- prompt_summary TEXT
- prompt_category TEXT
- created_at

Rolling window of last 100 prompts per user for pattern detection.


Context Injection

When a user sends a message, their preferences and any matching workflow are injected:

[User Preferences]
• Prefers concise responses
• Senior developer - skip basic explanations
• Always include code examples

[Known Workflow: roster_vehicle_extraction]
This user regularly does this task. Their preferred approach:
- Trigger: roster CSS/file + vehicles
- Output format: bullet list with times
You can proactively help without them re-explaining.

API Endpoints

GET /api/pdb/v1/reggie/preferences

List all learned preferences for current user.

GET /api/pdb/v1/reggie/workflows

List all learned workflows for current user.

GET /api/pdb/v1/reggie/context

Get combined preferences + workflows (preview what gets injected).

PATCH /api/pdb/v1/reggie/preferences/:id/toggle

Toggle preference active state.

{ "active": false }

DELETE /api/pdb/v1/reggie/preferences/:id

Remove a learned preference.

PATCH /api/pdb/v1/reggie/workflows/:id/toggle

Toggle workflow active state.

DELETE /api/pdb/v1/reggie/workflows/:id

Remove a learned workflow.

POST /api/pdb/v1/reggie/preferences

Manually add a custom preference.

{
"category": "output",
"preference": "include_sql",
"description": "Always show SQL queries"
}

UI Integration

A cog icon in the Reggie chat header opens a preferences modal:

┌─────────────────────────────────────────────┐
│ Your Reggie Preferences [x] │
├─────────────────────────────────────────────┤
│ Learned from your conversations │
│ │
│ ☑ Concise responses preferred │
│ ☑ Senior developer - skip basics │
│ ☑ Always show SQL queries │
│ ☐ Include code comments [Remove] │
│ │
│ ───────────────────────────────────────── │
│ Learned Workflows │
│ │
│ ☑ Roster Vehicle Extraction (used 12x) │
│ ☐ Staff Scheduling Report (used 3x) │
│ │
│ + Add custom preference │
│ [Save Changes] │
└─────────────────────────────────────────────┘

Analyzer Prompt

The GPT-4.1-nano analyzer receives:

{
"current_message": "user's message",
"similar_past_prompts": [
{ "summary": "...", "days_ago": 2, "similarity": 0.85 },
...
],
"match_count": 4,
"recent_context": [ /* last 4 messages */ ]
}

And returns:

{
"detected": "preference|workflow|pain_point|correction|none",
"preference": {
"category": "tone",
"preference": "concise",
"description": "Prefers concise responses",
"confidence": 0.85
},
"reasoning": "User said 'just give me the short version'"
}

Configuration

Env VariableDefaultDescription
REGGIE_PREFERENCE_LEARNINGtrueEnable/disable the system

The analyzer uses gpt-4.1-nano for speed and cost efficiency (~$0.20/1M tokens).


Integration with Context System

This system extends the existing Context v2.1:

  • v2.0: Session memory, recent/history summaries, topic inference
  • v2.1: LLM summaries, semantic search, personalized intros
  • v2.2: Preference learning, workflow detection, implicit task memory

All three layers work together:

[Personalized Intro - v2.1]
"Hey Lloyd! Last time we worked on the roster analysis..."

[Recent Context - v2.0]
• Previous session summaries...

[User Preferences - v2.2]
• Concise responses preferred
• Senior developer

[Known Workflow - v2.2]
• roster_vehicle_extraction (matched)

[Topic: Scheduling - v2.0]
• Topic-specific context...

Future Enhancements

  1. Periodic check-ins: "Quick check - are these preferences still accurate?"
  2. Workflow sharing: Share common workflows across team
  3. Confidence decay: Reduce confidence over time if not reinforced
  4. Category detection: Auto-categorize prompts (analysis, generation, lookup)
  5. Cross-session learning: Learn from corrections in real-time