How to Store Per-User Preferences for AI Agents

Free · Open source (MIT) · Works with LangChain, CrewAI, AutoGen · No signup

You're building an AI agent that should remember each user's preferences — their timezone, notification settings, or conversation style — but after each restart, it's back to asking the same questions. This is a core requirement for any production agent that needs user preferences ai agent functionality.

The Problem: Stateless Agents in a Stateful World

AI agents are inherently stateless. Each conversation starts from scratch unless you explicitly persist user data. Your agent might learn that User A prefers technical responses and User B wants casual explanations, but this knowledge vanishes when your process restarts or scales across multiple instances.

The pain is real: users get frustrated re-explaining their preferences, your agent feels "dumb," and personalization — the key differentiator of modern AI experiences — becomes impossible. You need per-user state that survives process restarts, scales across multiple instances, and doesn't require complex database setup.

Traditional solutions like Redis require infrastructure setup, databases need schemas and migrations, and simple JSON files don't work in distributed environments. You need something purpose-built for personalization ai agents.

The Fix: Persistent Key-Value Memory

BotWire Memory provides persistent, per-user storage that survives restarts and works across processes. Install and start storing user preferences immediately:

pip install botwire
from botwire import Memory

# Create user-specific memory namespace
user_memory = Memory(f"user-{user_id}")

# Store preferences
user_memory.set("timezone", "America/New_York")
user_memory.set("response_style", "technical")
user_memory.set("notifications", {"email": True, "slack": False})

# Retrieve preferences
timezone = user_memory.get("timezone")  # "America/New_York"
style = user_memory.get("response_style")  # "technical"

How It Works: Namespace-Based User Isolation

Each user gets their own memory namespace using Memory(f"user-{user_id}"). This creates complete data isolation while keeping the API simple. The memory persists to BotWire's backend automatically — no database setup required.

def get_user_preferences(user_id: str) -> dict:
    memory = Memory(f"user-{user_id}")
    
    return {
        "timezone": memory.get("timezone", "UTC"),
        "language": memory.get("language", "en"),
        "expertise_level": memory.get("expertise", "intermediate"),
        "preferred_examples": memory.get("examples", "code-heavy")
    }

def update_preference(user_id: str, key: str, value: any):
    memory = Memory(f"user-{user_id}")
    memory.set(key, value)
    print(f"Updated {key} for user {user_id}")

Cross-process persistence means if your agent runs on multiple servers or restarts, user preferences remain intact. The user profile agent storage automatically handles serialization of complex objects like dictionaries and lists.

For managing preferences at scale, you can list all stored keys and implement cleanup logic:

# List all preference keys for a user
memory = Memory(f"user-{user_id}")
all_keys = memory.list_keys()  # Returns list of all stored keys

# Clean up old preferences
memory.delete("old_preference_key")

Integration with AI Frameworks

For LangChain agents, BotWire includes a chat history adapter that maintains conversation context alongside preferences:

from botwire import BotWireChatHistory
from langchain.memory import ConversationBufferMemory

# Chat history with user-specific persistence
chat_history = BotWireChatHistory(session_id=f"user-{user_id}")
memory = ConversationBufferMemory(chat_memory=chat_history)

# Your agent now remembers both conversation context AND preferences
# Preferences stored separately in Memory(f"user-{user_id}")
# Chat history in BotWireChatHistory

For CrewAI, use the memory tools for agents to remember and recall user-specific information:

from botwire.memory import memory_tools

# Create user-specific memory tools
user_tools = memory_tools(f"user-{user_id}")

# Your CrewAI agents can now use remember(), recall(), and list_memory()
# tools to persist user preferences across crew executions

When NOT to Use BotWire

FAQ

Why not Redis or a database? Redis requires infrastructure setup and doesn't persist by default. Databases need schemas, migrations, and connection management. BotWire works immediately with zero config.

Is this actually free? Yes, permanently. 1000 writes/day per namespace, 50MB storage, unlimited reads. No API keys, no credit card, no surprises.

What about data privacy? You control the data. It's open source (MIT license), self-hostable, and you can run your own instance with a single FastAPI service.

Start Building Personalized Agents

User preferences transform generic chatbots into personalized AI assistants. Install BotWire and start building agents that actually remember their users.

pip install botwire

Get started at botwire.dev — no signup required.

Install in one command:

pip install botwire

Start free at botwire.dev