Memory

Persistent agent memory that works across sessions

The --memory flag and memory command enable persistent memory for agents, allowing them to remember context across sessions.

Quick Start

Show Memories

bash
praisonai memory show
Show stored memories example

Use Memory Flag

bash
# Enable memory for agent
praisonai "count to 5" --memory
With memory flag example

Usage

!Manage Persistent Memory

Enable Memory

bash
# Enable memory for agent (persists across sessions)
praisonai "My name is John" --memory

# Memory with user isolation
praisonai "Remember my preferences" --memory --user-id user123

Expected Output:

🧠 Memory enabled

╭─ Agent Info ─────────────────────────────────────────────────────────────────╮
│  👤 Agent: DirectAgent                                                       │
│  Role: Assistant                                                             │
│  Memory: Enabled (user: user123)                                            │
╰──────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Nice to meet you, John! I'll remember your name for future conversations.   │
╰──────────────────────────────────────────────────────────────────────────────╯

💾 Memory saved: name="John"

Memory Commands

Show Memory

bash
# Show 10 most recent memories (default)
praisonai memory show

# Change how many are shown
praisonai memory show --limit 25
praisonai memory show -l 25

# Isolate by user
praisonai memory show --user-id user123

Output:

╭─ Memory Statistics ──────────────────────────────────────────────────────────╮
│  Short-term: 5 items                                                        │
│  Long-term: 12 items                                                        │
│  Entities: 3 items                                                          │
│  Episodic: 8 items                                                          │
╰──────────────────────────────────────────────────────────────────────────────╯

List Memories

memory list is an alias for memory show — same output, added for parity with tools list, session list, and config list.

bash
# List memories (default: 10 most recent)
praisonai memory list

# Show a specific number
praisonai memory list --limit 25

# Isolate by user
praisonai memory list --user-id user123 --limit 5

memory show and memory list accept the same flags:

FlagTypeDefaultDescription
--user-idstrNoneUser ID for memory isolation
--limit, -lint10Number of memories to show

Add Memory

bash
praisonai memory add "User prefers Python"

Search Memory

bash
praisonai memory search "Python"

Clear Memory

bash
# Clear short-term memory (the default target)
praisonai memory clear

# Clear everything
praisonai memory clear all

memory clear and memory clear all prompt for confirmation, matching the memory learn clear sibling command’s flow:

bash
$ praisonai memory clear all </dev/null
Clear ALL memories? This cannot be undone. [y/N]: Cancelled.   # EXIT=1, memory intact

$ praisonai memory clear all --force
✅ All memory cleared                                          # EXIT=0
TargetClearsNotes
shortShort-term memory onlyDefault when no target is given
allEverythingNow a valid target argument and works end-to-end
FlagShortDescription
--force-fSkip the confirmation prompt (required for scripts/CI)
--user-idScope the clear to a single user’s memories

An unknown target (anything other than short/all) exits 2; aborting the prompt exits 1 with nothing cleared.

Session Management

bash
# Save session
praisonai memory save my_session

# Resume session
praisonai memory resume my_session

# List saved sessions
praisonai memory sessions

Checkpoints

bash
# Create checkpoint
praisonai memory checkpoint

# Restore checkpoint
praisonai memory restore <checkpoint_id>

# List checkpoints
praisonai memory checkpoints

Help

bash
praisonai memory help

Memory Types

TypeDescriptionPersistence
Short-termRolling buffer of recent contextAuto-expires
Long-termImportant facts sorted by importancePersistent
EntityPeople, places, organizationsPersistent
EpisodicDate-based interaction historyPersistent

How It Works

  1. Capture: Agent extracts important information from conversations
  2. Categorize: Information is sorted into memory types
  3. Store: Memories are persisted to storage
  4. Inject: Relevant memories are injected into future conversations
Diagram

Facts

Context

Entities

Events

Conversation

Extract Info

Categorize

Long-term

Short-term

Entity

Episodic

Storage

Future Conversations

Storage Options

OptionDependenciesDescription
memory=TrueNoneFile-based JSON storage (default)
memory="file"NoneExplicit file-based storage
memory="sqlite"Built-inSQLite with indexing
memory="chromadb"chromadbVector/semantic search

Programmatic Usage

python
from praisonaiagents import Agent
from praisonaiagents import FileMemory

# Enable memory with a single parameter
agent = Agent(
    name="Personal Assistant",
    instructions="You are a helpful assistant that remembers user preferences.",
    memory={"user_id": "user123"}  # Enables memory with user isolation
)

# Memory is automatically injected into conversations
result = agent.start("My name is John and I prefer Python")
# Agent will remember this for future conversations

Advanced Features

python
from praisonaiagents import FileMemory

memory = FileMemory(memory={"user_id": "user123"})

# Session Save/Resume
memory.save_session("project_session", conversation_history=[...])
memory.resume_session("project_session")

# Context Compression
memory.compress(llm_func=lambda p: agent.chat(p), max_items=10)

# Checkpointing
memory.create_checkpoint("before_refactor", include_files=["main.py"])
memory.restore_checkpoint("before_refactor", restore_files=True)

# Slash Commands
memory.handle_command("/memory show")
memory.handle_command("/memory save my_session")

Best Practices

DoDon’t
Use user isolation for multi-user appsShare memory across users
Clear short-term memory regularlyLet memory grow unbounded
Use checkpoints before major changesSkip backups
Search before adding duplicatesAdd redundant memories

Related