Skip to main content
Session stores persist chat history and metadata — swap the default JSON backend or use hierarchical forks without changing your agent code.
The user chats across restarts; the session store persists history under ~/.praisonai/sessions/.

How It Works

Quick Start

1

Persist with session_id

Default files live at ~/.praisonai/sessions/{session_id}.json.
2

Use the store directly

Core Exports

SqliteSessionStore

SqliteSessionStore is a drop-in subclass of DefaultSessionStore that keeps JSON transcripts as the durable record and maintains a stdlib sqlite3 index alongside them. It gives you two indexed hot paths instead of directory scans:
  • Cross-session search — FTS5 index of message content, used by search() (Issue #2927).
  • Gateway/agent routingsession_route index of gateway_session_id and agent_id, used by get_by_gateway_session() and list_sessions_by_gateway_agent() (Issue #2956).
Both stay independent of the number of stored sessions, so a long-lived gateway bot with thousands of sessions still routes an inbound message in a single indexed lookup.

Constructor

Behaviour

Fallback matrix

Sizing

  • Each row in session_fts holds the flattened concatenation of a session’s message content (newline-joined). Large transcripts increase index size roughly linearly.
  • Use ":memory:" for ephemeral tests; use the default disk path for gateway bots that need durability across restarts.
Bookends, automated demotion, and lineage dedup apply to results from both stores — see Cross-Session Recall.

Compaction Checkpoints

When context compaction runs during a conversation, the store can persist the summary so a later resume replays the compacted working history (summary + retained tail) instead of the full raw transcript. See Compacted Session Resume for the end-to-end agent flow.

Store Methods

SessionData additions

SessionData.last_compaction holds the latest CompactionCheckpoint (or None). Two helpers support cheap resume:
set_chat_history() and clear_session() both clear last_compaction — replacing or clearing the transcript invalidates the anchor.

Task-Local Context

Best Practices

Let Agent(memory={"session_id": "..."}) handle persistence — use the store directly only for admin, migration, or custom backends.
Switch to get_hierarchical_session_store() when you need branching conversations or revert — see Session Hierarchy.
Call set_session_context() at the start of each async task so downstream code reads the correct session without threading IDs through every call.

Session Persistence

Agent-centric session_id usage

Session Hierarchy

Forking and snapshots

Cross-Session Recall

Search past sessions — anchored, demoted, deduped results