The memory module provides a sophisticated multi-tiered memory system with short-term, long-term, entity, and user-specific memory capabilities, including graph database support and quality scoring.
from praisonaiagents import Memory# Initialize memory systemmemory = Memory()# Store informationmemory.add( text="The user prefers Python over JavaScript", memory_type="long")# Search memoriesresults = memory.search("programming preferences")# Build context for agentscontext = memory.build_context_for_task( task_description="Help with a Python project", max_items=5)
3
Advanced graph memory
Copy
from praisonaiagents import Memory# Initialize with graph supportmemory = Memory( graph_enabled=True, graph_uri="bolt://localhost:7687", graph_user="neo4j", graph_password="password")# Store entity relationshipsmemory.add( text="John works at TechCorp as a Senior Developer", memory_type="entity")# Query graph relationshipsresults = memory.search("Who works at TechCorp?")
build_context_for_task( task_description: str, max_items: int = 10) -> str
Example output:
Copy
Based on memory:- User prefers Python for data science projects- Previous experience with pandas and numpy- Interested in machine learning applications
from praisonaiagents.memory import MemoryClient# Initialize memorymemory = MemoryClient(verbose=2)# Store memoriesmemory.store_in_short_memory("User asked about pricing")memory.store_in_long_memory( "Company pricing: $99/month for pro plan", quality_score=0.9)# Search memoriesresults = memory.search_memories("pricing", k=5)
# Store entity informationmemory.store_entity_memory( name="Acme Corp", entity_type="Company", desc="Leading provider of AI solutions", relations=["Founded by John Doe", "Partnered with TechCo"], user_id="user123")# Retrieve entity contextcontext = memory.build_context_for_task( "Tell me about Acme Corp's partnerships")
from praisonaiagents import Agent# Agent with memoryagent = Agent( name="Assistant", role="Helpful AI assistant", memory=True, # Enable memory memory_config={ "provider": "rag", "use_embedding": True })# Memory is automatically managed during conversationsresponse = agent.chat("Remember that my favorite color is blue")
# Configure with Neo4jmemory = MemoryClient({ "provider": "mem0", "config": { "graph_store": { "provider": "neo4j", "config": {...} } }})# Store with relationshipsmemory.memory.add( "John Doe is the CEO of Acme Corp", metadata={"entities": ["John Doe", "Acme Corp"]})# Graph-aware searchresults = memory.search_memories( "Who works at Acme Corp?", rerank=True)
from praisonaiagents import Memorymemory = Memory(quality_threshold=0.8)# High-quality informationmemory.add( "User's API key: sk-abc123def456", memory_type="long", quality_score=0.9)# Low-quality information (won't be stored in long-term)memory.add( "User said hello", memory_type="long", quality_score=0.3)# Get only high-quality memoriesimportant = memory.get_quality_memories(min_quality=0.8)
from praisonaiagents import Memory# Setup graph memorymemory = Memory( graph_enabled=True, graph_uri="bolt://localhost:7687", graph_user="neo4j", graph_password="password")# Store entity relationshipsmemory.add( "Alice manages Bob and Charlie at DataCorp", memory_type="entity")memory.add( "DataCorp acquired SmallStartup in 2024", memory_type="entity")# Query relationshipsresults = memory.search("Who does Alice manage?")# Returns information about Bob and Charlieresults = memory.search("DataCorp acquisitions")# Returns information about SmallStartup acquisition
from praisonaiagents import Memory, Agent, PraisonAIAgents# Shared memory systemshared_memory = Memory(provider="rag")# Create agents with shared memoryresearcher = Agent( name="Researcher", role="Research Analyst", memory=shared_memory)writer = Agent( name="Writer", role="Content Creator", memory=shared_memory)# Researcher stores findingsresearcher.chat("Found that 73% of users prefer dark mode")# Writer can access the same memoryresponse = writer.chat("Write about user preferences")# Uses the 73% statistic from shared memory
Short-term: Conversation context, temporary state
Long-term: Facts, preferences, important information
Entity: People, places, organizations, relationships
User: Personal data, settings, history
Quality Management
Set appropriate quality thresholds (0.7-0.8 recommended)
Manually score critical information higher
Periodically review and clean low-quality memories