from praisonaiagents import Agentagent = Agent( name="Assistant", instructions="You are a helpful assistant with memory.", memory=True)agent.start("Remember that I prefer Python for data science")
2
With config
from praisonaiagents import Agentagent = Agent( name="Assistant", instructions="You are a helpful assistant with memory.", memory={ "backend": "rag", "user_id": "user123", "use_embedding": True })
Long-term memory persists across sessions and stores important information.
# Store persistent knowledgememory.store_long_term( text="User works as a data scientist at TechCorp", memory={"user_id": "user123"}, quality=0.95, metadata={"type": "user_info", "category": "professional"})# Retrieve with quality filtermemories = memory.search_long_term( query="user profession", memory={"user_id": "user123"}, min_quality=0.8)
Entity memory stores information about specific people, places, or things.
# Store entity informationmemory.store_entity( name="TechCorp", text="TechCorp is a leading AI company founded in 2020", entity_type="organization", metadata={"industry": "technology", "size": "large"})# Search entity informationentity_info = memory.search_entity( name="TechCorp", query="company details")
PraisonAI automatically falls back to SQLite when a configured backend (Redis, Valkey, Postgres) is unavailable, so your agent keeps working without crashing.
from praisonaiagents import Agent, MemoryConfig# Configure Redis — if redis-py isn't installed,# PraisonAI falls back to SQLite automatically.agent = Agent( name="Assistant", instructions="You remember user preferences.", memory=MemoryConfig(backend="redis", user_id="user_123"))agent.start("Remember I prefer dark mode")
Configured backend
Fallback when unavailable
Search/store path
redis
SQLite (adapter)
memory_adapter.search_* / store_*
valkey
SQLite (adapter)
memory_adapter.search_* / store_*
postgres
SQLite (adapter)
memory_adapter.search_* / store_*
sqlite
n/a (native)
memory_adapter.* (direct)
file
n/a (native)
FileMemory (direct)
mem0
raises ImportError
direct Mem0 client
mongodb
raises error
direct Mongo client
Before the fix in PraisonAI PR #2190, configuring backend="redis" without redis-py installed produced sqlite3.OperationalError: no such table: short_mem on the first memory call. The SQLite adapter now owns the correct schema (short_term_memory / long_term_memory), so fallback is transparent.
Symptom: sqlite3.OperationalError: no such table: short_mem
Cause: You are running a version of PraisonAI before PR #2190. A non-default backend (e.g. redis) was configured but its dependency was not installed, causing a silent fallback to SQLite — which then queried the legacy short_mem table that no longer exists.Fix: Upgrade PraisonAI to the release that includes PR #2190, or install the dependency for your configured backend (e.g. pip install redis for Redis).
Memory results are deterministically ordered for prompt caching effectiveness. Use build_context_for_task() with explicit output control for manual prompt assembly.
from praisonaiagents import Memorymemory = Memory(config={"provider": "rag"})context = memory.build_context_for_task( task_descr="Research the latest AI developments", user_id="user_123", max_items=3, include_in_output=True # Force include for prompt assembly)# Construct cache-friendly prompt structuresystem_prompt = f"System instructions and tools\n\n{context}\n\nUser message: {{user_input}}"
from praisonaiagents import Agent, Task, AgentTeamfrom praisonaiagents import Memory# Configure memory with quality scoringmemory_config = { "provider": "rag", "use_embedding": True, "embedding_model": "text-embedding-3-small"}# Create memory instancememory = Memory(memory_config)# Create assistant agentassistant = Agent( name="Personal Assistant", instructions="""You are a personal assistant with perfect memory. Remember user preferences, important information, and context. Always use your memory to provide personalised responses.""", memory={"user_id": "john_doe"} # Memory with user isolation)# Create task with memory integrationtask = Task( description="Help me plan my day based on my preferences", agent=assistant, expected_output="Personalised daily schedule")# Run the systemagents = AgentTeam( agents=[assistant], tasks=[task], memory=True # Enable shared memory)# Memory automatically:# 1. Retrieves user preferences# 2. Searches relevant past interactions# 3. Builds context for the task# 4. Stores the interaction with quality scoreresult = agents.start()# Store user feedback as high-quality memorymemory.store_long_term( text="User preferred morning schedule with exercise first", memory={"user_id": "john_doe"}, completeness=0.9, relevance=1.0, clarity=0.95, accuracy=1.0)
AutoMemory wraps FileMemory with a pattern-based extraction engine. After each agent interaction, it scans the conversation for matching patterns (preferences, facts, dates, etc.) and stores them automatically.
from praisonaiagents import Agent, MemoryConfig# Enable auto-memory extractionagent = Agent( name="Assistant", instructions="You are a helpful assistant.", memory=MemoryConfig(auto_memory=True, user_id="user123"))# Patterns are extracted automatically from conversationagent.start("I prefer Python for data science and I'm based in London")# AutoMemory stores: preference="Python for data science", location="London"