Preference Tracking
DeskBot's preference tracker learns user preferences from conversation text — name, volume, pace, formality, humour, verbosity, language — and stores them with confidence scores so the robot can personalise its behaviour over time.
How it works
The PreferenceTracker analyses
each user utterance for explicit preference statements (e.g. "my name is
Alice", "be funny", "slow down"). When a pattern matches, it creates
or updates a Preference in the store
with a confidence score that increases on repeated observations.
Confidence boosting
| Source | Confidence boost per observation |
|---|---|
explicit |
+0.3 |
inferred |
+0.1 |
Confidence is capped at 1.0. First explicit observation starts at 0.5, first inferred observation at 0.2.
Supported categories
| Key | Patterns (examples) | Possible values |
|---|---|---|
name |
"my name is …", "I'm called …", "call me …" | Any string |
nickname |
"my nickname is …" | Any string |
volume |
"louder", "quieter", "too loud", "turn it down" | high, low |
pace |
"slower", "faster", "slow down", "speed up" | slow, fast |
formality |
"be formal", "be casual", "talk casually" | formal, casual |
humour |
"be funny", "be serious", "more jokes" | humorous, serious |
verbosity |
"be brief", "more detail", "be verbose" | brief, detailed |
language |
"speak English", "en español", "speak French" | en, es, fr, de |
Usage
from robot.ai.preferences import PreferenceTracker, InMemoryPreferenceStore
# Create a tracker with an in-memory store
tracker = PreferenceTracker()
# Process user utterances
updated = tracker.process_user_text("My name is Alice")
# -> [Preference(key='name', value='alice', confidence=0.5, source='explicit')]
updated = tracker.process_user_text("Be funny")
# -> [Preference(key='humour', value='humorous', confidence=0.5, source='explicit')]
# Retrieve a specific preference
pref = tracker.get("name")
# Preference(key='name', value='alice', confidence=0.5, source='explicit')
# Format preferences for an LLM system prompt
prompt_text = tracker.format_for_prompt()
# "User preferences:\n- name: alice (confidence: 50%, source: explicit)\n- humour: humorous ..."
With SQLite persistence
from robot.ai.preferences import PreferenceTracker, SqlitePreferenceStore
store = SqlitePreferenceStore(db_path="preferences.db")
tracker = PreferenceTracker(store=store)
# Preferences are persisted to disk automatically
tracker.process_user_text("My name is Bob")
# Later, in a different session:
tracker2 = PreferenceTracker(store=SqlitePreferenceStore(db_path="preferences.db"))
name = tracker2.get("name")
# Preference(key='name', value='bob', ...)
Store backends
InMemoryPreferenceStore
Simple dict-backed store for testing. Preferences are lost when the process exits.
SqlitePreferenceStore
SQLite-backed store using a preferences table with columns
(key, value, confidence, source, updated_at). Use a file path for
persistence or ":memory:" for testing.
Integration with conversation
The PreferenceTracker is typically wired into the conversation service.
After each user utterance is transcribed, process_user_text() is called
and any discovered preferences are injected into the system prompt for the
next LLM call via format_for_prompt().
API reference
robot.ai.preferences.Preference
dataclass
A single learned preference.
Attributes
key:
The preference category (e.g. "humour", "volume").
value:
The learned value (e.g. "dry", 0.7).
confidence:
How confident the tracker is, in [0, 1].
source:
How this preference was learned ("explicit" for direct
statements, "inferred" for deduced preferences).
updated_at:
When the preference was last updated.
observation_count:
Number of observations contributing to this preference.
total_reward:
Cumulative reward associated with this preference.
first_observed / last_observed:
Timestamps defining the observation history.
Source code in src/robot/ai/preferences.py
robot.ai.preferences.PreferenceStore
Bases: Protocol
Storage backend for preferences.
Source code in src/robot/ai/preferences.py
close()
delete(key)
load(key)
load_all()
robot.ai.preferences.PreferenceTracker
dataclass
Learns user preferences from conversation events.
The tracker analyses each user utterance for explicit preference statements (e.g. "my name is Alice", "be funny") and infers preferences from repeated patterns. Preferences are stored with confidence scores that increase with repeated observations.
Negation handling
Phrases like "don't be funny" are detected and skipped rather than incorrectly learning the opposite of what was intended. This prevents a user saying "I don't want you to be funny" from being recorded as preferring humour.
Source code in src/robot/ai/preferences.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
format_for_prompt(limit=10)
Format preferences as a human-readable string for system prompts.
Only includes preferences above a minimum confidence threshold.
Source code in src/robot/ai/preferences.py
get(key)
get_all()
process_user_text(text)
Analyse a user utterance for preferences.
Returns any newly created or updated preferences.
Handles negation: "don't be funny" is skipped rather than recording a preference for humour.
Source code in src/robot/ai/preferences.py
robot.ai.preferences.InMemoryPreferenceStore
Simple dict-backed store for testing.
Source code in src/robot/ai/preferences.py
robot.ai.preferences.SqlitePreferenceStore
SQLite-backed preference store.
Uses a single table preferences containing both the normal
preference state and learner metadata.
Source code in src/robot/ai/preferences.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
__init__(db_path=':memory:')
Create a SQLite-backed preference store.
:memory: is kept as SQLite's special in-memory database name.
File-backed databases are expanded and their parent directory is
created automatically.
Source code in src/robot/ai/preferences.py
load_learned_all()
Load all preferences with full learner state.
Returns a list of dicts with all persisted fields,
suitable for reconstructing :class:LearnedPreference objects.
Source code in src/robot/ai/preferences.py
save(preference)
Persist the complete preference state.
Source code in src/robot/ai/preferences.py
save_learned(key, value, confidence, source, updated_at, observation_count, total_reward, first_observed, last_observed)
Persist the full learner state for a preference.
This is the canonical persistence path for
:class:PreferenceLearner - it stores all fields needed to
reconstruct the learner's internal state exactly.