PraisonAI Agents provides automatic session persistence with zero configuration. Simply provide a session_id to your Agent and conversation history is automatically saved and restored.
from praisonaiagents import Agent# First conversationagent = Agent( name="Assistant", memory={"session_id": "my-session-123"})agent.start("My name is Alice and I love pizza")# Later, in a new process - history is restored automaticallyagent = Agent( name="Assistant", memory={"session_id": "my-session-123"})agent.start("What is my name?") # Agent remembers: "Alice"
Even without session_id, the same Agent instance remembers previous messages:
Copy
from praisonaiagents import Agentagent = Agent(name="Assistant")# First messageagent.chat("My favorite number is 42")# Second message - agent remembersagent.chat("What is my favorite number?") # Agent responds: "42"
In-memory memory is lost when the Agent instance is garbage collected or the process ends.
Use session_id for persistence across processes.
from praisonaiagents import Agent# Create agent with session_idagent = Agent( name="Assistant", instructions="You are a helpful assistant.", memory={"session_id": "user-123-chat"})# Conversation is automatically persistedresponse = agent.chat("Remember that my birthday is January 15th")
# In a new Python process or after restartfrom praisonaiagents import Agent# Same session_id restores historyagent = Agent( name="Assistant", instructions="You are a helpful assistant.", memory={"session_id": "user-123-chat"})# Agent remembers previous conversationresponse = agent.chat("When is my birthday?")# Agent responds: "Your birthday is January 15th"
All session stores implement SessionStoreProtocol — a lightweight interface that enables swapping backends:
Copy
from praisonaiagents.session import SessionStoreProtocol# Any class with these 5 methods satisfies the protocol:# add_message(), get_chat_history(), clear_session(),# delete_session(), session_exists()assert isinstance(get_default_session_store(), SessionStoreProtocol)