Skip to main content
Memory lets agents remember past conversations, user preferences, and context across sessions.
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful personal assistant.",
    memory=True,
)

agent.start("My name is Alice and I prefer concise answers.")
The user shares preferences in chat; the agent recalls them in later sessions via the configured memory backend.

Quick Start

1

Level 1 — Bool (simplest)

Turn on memory with a single flag — the agent remembers across turns using the default file backend.
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory=True,
)
agent.start("Remember that I work in software engineering.")
2

Level 2 — String (pick a backend)

Pass a backend name to choose where memories are stored.
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory="sqlite",
)
agent.start("Remember that I prefer concise answers.")
3

Level 3 — Config class (full control)

Use MemoryConfig to scope memory per user and auto-extract facts.
from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory=MemoryConfig(
        backend="sqlite",
        user_id="alice",
        auto_memory=True,
    ),
)
agent.start("What do you know about my preferences?")
4

Level 4 — Config with continuous learning

Add LearnConfig to build a long-term persona alongside session memory.
from praisonaiagents import Agent, MemoryConfig, LearnConfig

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory=MemoryConfig(
        backend="redis",
        user_id="alice",
        learn=LearnConfig(persona=True, insights=True, mode="agentic"),
    ),
)
agent.start("I always want answers formatted as bullet points.")

How It Works

PhaseWhat happens
1. StoreEach conversation turn is saved to the memory backend
2. RetrieveRelevant past context is recalled before responding
3. RespondAgent answers with full historical context available

Which Backend to Choose?


Configuration Options

Full list of options, types, and defaults — MemoryConfig
The most common options at a glance:
OptionTypeDefaultDescription
backendstr"file"Storage backend: file, sqlite, redis, postgres, mem0, mongodb
user_idstr | NoneNoneUser identifier for scoped memory
auto_memoryboolFalseAuto-extract and store key facts
learnbool | LearnConfig | NoneNoneEnable continuous learning
historyboolFalseAuto-inject session history into context

Common Patterns

Pattern 1 — User-scoped memory

from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    instructions="You are a personal assistant.",
    memory=MemoryConfig(user_id="user_alice", backend="sqlite"),
)
response = agent.start("What have I told you about my work preferences?")
print(response)

Pattern 2 — History injection for conversation continuity

from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    instructions="You are a support agent.",
    memory=MemoryConfig(history=True, history_limit=5),
)
agent.start("Continue from where we left off.")

Best Practices

Without user_id, all users share the same memory store. Set user_id to a unique identifier per user to keep memories properly scoped and private.
Enable auto_memory=True to have the agent automatically identify and store important facts from each conversation — names, preferences, decisions — without extra code.
Set learn=True inside MemoryConfig to enable continuous learning alongside session memory. This gives agents both short-term context (memory) and long-term pattern recognition (learn).
Start with file, move to sqlite when you need durability, then redis when you deploy multiple agent instances that share memory.

Learn

Learn — continuous learning from conversations

Knowledge

Knowledge — add documents and URLs as agent knowledge