Skip to main content
Stateful agents remember conversations, persist workflow state, and recall context across sessions.
The user shares preferences; session memory persists them for later turns.

Quick Start

1

Simple Usage

Enable memory on an agent with a user scope:
2

With Session

Use Session for persistent multi-turn state:

How It Works

Core Stateful Capabilities

Memory System

PraisonAI includes a sophisticated multi-tiered memory system with quality-based filtering:
  • Short-term Memory (STM): Ephemeral context for current conversations
  • Long-term Memory (LTM): Persistent knowledge with quality-based filtering
  • Entity Memory: Structured data about named entities and relationships
  • User Memory: User-specific preferences and interaction history
  • Graph Memory: Complex relationship storage via Mem0 integration

Session Management

The Session class provides a unified API for managing stateful agent interactions:

Workflow State Management

PraisonAI supports complex stateful workflows with persistent state across steps:

Advanced Stateful Patterns

Quality-Based Memory Storage

Memory storage with automatic quality assessment using individual metrics:

Enhanced State Management

Context Building from Multiple Sources

For multi-turn chats on Anthropic or Google, use build_context_for_task() with include_in_output=True for cache-friendly prompt assembly. See Prompt Caching.

Knowledge Base Integration

Advanced Memory Features

Graph Memory Support

Quality Metrics and Evaluation

Session API Updates

Current Session Methods

Configuration Examples

Basic Stateful Agent

Advanced Memory Configuration

Complex Workflow with State

Best Practices

Always pass a unique session_id per user. This isolates state and memory between different users in multi-tenant applications.
Use "rag" for local embeddings, "mem0" for cloud-based memory with semantic search, and "none" when you only need workflow state without semantic retrieval.
Call session.save_state() after significant workflow milestones, not after every message. This reduces I/O and keeps state snapshots meaningful.
Configure quality_threshold on memory to automatically filter out low-quality interactions from long-term memory, keeping retrieval fast and relevant.

Sessions

Session management and persistence

Memory Advanced Search

Reranking and relevance filtering for memory retrieval