Skip to main content
Sessions enable your agents to remember conversations across restarts. Just add a session_id to your agent’s memory configuration.

Quick Start

1

Install PraisonAI Agents

2

Create Agent with Session

3

Resume Later

Default Storage: ~/.praisonai/sessions/{session_id}.json

How It Works

Configuration Options

For full control, use the MemoryConfig class:

Using Dict Shorthand

For quick setup, use a dictionary:

Database Persistence

For production apps, persist sessions to a database:

Multi-User Sessions

For apps with multiple users, include user_id to isolate conversations:

Using the Session Class

For advanced control over memory and knowledge, use the Session class:

Advanced Topics

For complex workflows, use hierarchical sessions with forking and snapshots:
See Session Hierarchy for full documentation.
Connect to agents running on remote machines:
Remote sessions don’t support local memory operations.
Implement the DbAdapter protocol for custom persistence:
See Database Adapters for full protocol.
For low-level control, access the session store directly:
Atomic batch replace — when you need to rewrite the whole history under a single lock (compaction, redaction, multi-worker bot saves):
Safer than clear_session() + a loop of add_message() — there is no window where another worker can read an empty history.

Best Practices

Use Meaningful Session IDs

Include user ID or task context: user-123-main, task-456-research

Isolate Users

Always include user_id in multi-user apps to prevent data leakage

Choose Right Backend

JSON for dev, SQLite for single-server, PostgreSQL for production

Set Message Limits

Use max_messages to prevent unbounded growth

Session ID Patterns

CLI Commands

Session Lifecycle & Cleanup

Session.close() now properly invokes memory.close_connections(), which closes the underlying adapter (ChromaDB references, MongoDB client, etc.):

Automatic Cleanup Example

Troubleshooting

  • Verify session_id is exactly the same
  • Check storage directory exists: ~/.praisonai/sessions/
  • Ensure file permissions allow read/write
  • Try invalidating cache: store.invalidate_cache(session_id)
  • Another process may be holding the lock
  • Increase lock_timeout parameter
  • Check for stale .lock files and remove them
  • Set max_messages limit on DefaultSessionStore
  • Use get_chat_history(max_messages=50) to limit retrieval
  • Consider using SQLite backend for better performance
  • Verify agent URL is correct and accessible
  • Check firewall/network settings
  • Ensure remote agent has /health endpoint
  • Increase timeout parameter for slow networks

API Reference

Agent Session Parameters

The memory parameter on Agent accepts these session-related options:

Session Class Parameters

Session Persistence

Detailed persistence options

Session Hierarchy

Forking and snapshots

Memory System

Memory integration

CLI Commands

Command-line management