Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SET USER MEMORY

Persists data at the user level, accessible across sessions and bots. Unlike SET BOT MEMORY which stores data per-bot, user memory follows the user wherever they go.

Syntax

SET USER MEMORY "key", value

Parameters

ParameterTypeDescription
keyStringUnique identifier for the stored value
valueAnyThe value to store (string, number, object)

Description

SET USER MEMORY stores persistent data associated with a specific user. This data:

  • Persists across sessions - Available when user returns days/weeks later
  • Persists across bots - Accessible from any bot the user interacts with
  • Survives restarts - Stored in the database, not just memory
  • Supports TTL - Optional time-to-live for automatic expiration

This is ideal for user preferences, profile data, and cross-bot personalization.

Examples

Basic Usage

' Store user preferences
SET USER MEMORY "language", "pt-BR"
SET USER MEMORY "timezone", "America/Sao_Paulo"
SET USER MEMORY "theme", "dark"

TALK "Preferences saved!"

Store Complex Objects

' Store user profile
profile = #{ 
    name: username,
    email: useremail,
    plan: "premium",
    signupDate: NOW()
}
SET USER MEMORY "profile", profile

TALK "Profile updated successfully!"

Cross-Bot Data Sharing

' In sales-bot: Store purchase history
purchase = #{
    orderId: orderid,
    amount: total,
    date: NOW()
}
SET USER MEMORY "lastPurchase", purchase

' In support-bot: Access the same data
lastPurchase = GET USER MEMORY("lastPurchase")
TALK "I see your last order was #" + lastPurchase.orderId

User Preferences for Personalization

' Check if returning user
name = GET USER MEMORY("name")

IF name = "" THEN
    TALK "Welcome! What's your name?"
    HEAR name
    SET USER MEMORY "name", name
    TALK "Nice to meet you, " + name + "!"
ELSE
    TALK "Welcome back, " + name + "!"
END IF

Store User Facts

' Store facts about the user for AI context
SET USER MEMORY "fact_occupation", "software engineer"
SET USER MEMORY "fact_interests", "AI, automation, productivity"
SET USER MEMORY "fact_company", "Acme Corp"

' These can be used to personalize AI responses
KeywordDescription
GET USER MEMORYRetrieve user-level persisted data
SET BOT MEMORYStore data at bot level
GET BOT MEMORYRetrieve bot-level data
USER FACTSGet all stored user facts

Database Storage

User memory is stored in the user_memory table with the following structure:

ColumnDescription
user_idThe user’s unique identifier
keyThe memory key
valueJSON-encoded value
memory_typeType classification (preference, fact, context)
ttlOptional expiration timestamp
created_atWhen the memory was created
updated_atLast modification time

Config.csv Options

name,value
user-memory-enabled,true
user-memory-max-keys,1000
user-memory-default-ttl,0
OptionDefaultDescription
user-memory-enabledtrueEnable/disable user memory
user-memory-max-keys1000Maximum keys per user
user-memory-default-ttl0Default TTL in seconds (0 = no expiry)

Best Practices

  1. Use descriptive keys - user_language not lang
  2. Prefix related keys - pref_theme, pref_language, fact_name
  3. Don’t store sensitive data - No passwords or tokens
  4. Consider TTL for temporary data - Session-specific data should expire
  5. Keep values reasonable size - Don’t store large files or blobs

See Also