AI Memory and Conversation Management Framework - Simple as mem0, Powerful as PersonaLab
Project description
PersonaLab
๐ง AI Memory and Conversation Management Framework - Simple as mem0, Powerful as PersonaLab
๐ PersonaLab v0.1.0 is now available on PyPI! - The first official release with stable PostgreSQL-based memory system and multi-LLM support.
PersonaLab is a comprehensive AI memory and conversation management system that provides intelligent profile management, conversation recording, and advanced semantic search capabilities for AI agents. It combines persistent memory storage, conversation analysis, psychological modeling, and vector-based retrieval for building sophisticated AI applications.
๐ฆ Installation
From PyPI (Recommended)
# Basic installation
pip install personalab
# With AI features (includes OpenAI support)
pip install personalab[ai]
# Full installation (all LLM providers and features)
pip install personalab[all]
From Source (Development)
git clone https://github.com/NevaMind-AI/PersonaLab.git
cd PersonaLab
pip install -e .
# For development
pip install -r requirements-dev.txt
pre-commit install
โก Quick Start
๐ก Important: All PersonaLab chat interactions require a
user_idparameter to identify different users and maintain separate memory spaces for each user.
Simple 3-Line Setup
from personalab import Persona
# Create an AI persona with memory
persona = Persona(agent_id="my_assistant")
# Chat with persistent memory across sessions
response = persona.chat("Hi, I'm learning Python", user_id="student_123")
print(response)
# Memory is automatically managed!
Complete Example with Memory & LLM Configuration
from personalab import Persona
from personalab.llm import OpenAIClient, AnthropicClient
# Configure your LLM client
openai_client = OpenAIClient(api_key="your-key", model="gpt-4")
# Create persona with full features
persona = Persona(
agent_id="programming_tutor",
llm_client=openai_client,
personality="You are a helpful and friendly programming tutor.",
use_memory=True, # ๐ง Long-term memory (facts, preferences, events)
use_memo=True # ๐ฌ Conversation history & semantic search
)
# Chat with memory
user_id = "student_123"
response1 = persona.chat("I'm learning machine learning", user_id=user_id)
response2 = persona.chat("What did I mention I was learning?", user_id=user_id)
# End session to update memories
persona.endsession(user_id)
# Get stored memories
memory_info = persona.memory_client.get_memory_by_agent(persona.agent_id, user_id)
profile = memory_info.get_profile()
events = memory_info.get_events()
print(f"Profile: {profile}")
print(f"Events: {len(events)} stored")
Environment Setup
# 1. Copy environment template (if using from source)
cp .env.example .env
# 2. Add your API keys to .env
echo "OPENAI_API_KEY=your_openai_key_here" >> .env
echo "ANTHROPIC_API_KEY=your_anthropic_key_here" >> .env
# 3. Test configuration
python -c "from personalab import Persona; print('โ
PersonaLab ready!')"
๐ Key Features
๐พ Intelligent Memory System
- ๐ง Agent Memory: Persistent profile and event storage for AI agents
- ๐ค User Memory: Individual memory spaces for different users
- ๐ Profile Management: Automatic profile updates based on conversations
- ๐ Event Tracking: Comprehensive conversation and interaction history
- ๐ง Theory of Mind: Psychological analysis and behavioral insights
๐ฌ Advanced Conversation Management
- ๐ Conversation Storage: Structured recording with metadata (user_id, agent_id, timestamps)
- ๐ Vector Embeddings: High-quality semantic embeddings for intelligent search
- ๐ฏ Semantic Search: Retrieve relevant conversations based on meaning, not just keywords
- ๐ Session Management: Organized conversation tracking and session handling
- โก Multiple Providers: OpenAI, SentenceTransformers, and more embedding options
๐ค Multi-LLM Integration
- ๐ Multiple Providers: OpenAI, Anthropic, Google Gemini, Azure OpenAI, Cohere, AWS Bedrock, Together AI, Replicate
- ๐ Intelligent Search: LLM-powered decision making and content analysis
- ๐ Profile Updates: AI-driven profile enhancement from conversation content
- ๐ง Flexible Configuration: Easy switching between LLM providers and models
๐ Advanced Search & Analysis
- ๐ง LLM-Enhanced Search: Semantic understanding and relevance scoring
- โก Vector Similarity: Fast and accurate conversation retrieval
- ๐ฏ Intent Analysis: Intelligent extraction of search requirements
- ๐ Context-Aware Results: Ranked results based on conversation context
๐ Requirements
- Python: 3.8 or higher
- Database: PostgreSQL (required for memory storage)
- LLM API Keys: OpenAI, Anthropic, or other supported providers
Database Setup
PersonaLab requires PostgreSQL for memory storage. Quick setup:
# Using Docker (recommended)
docker run --name personalab-postgres -e POSTGRES_PASSWORD=your_password -p 5432:5432 -d postgres:14
# Or install PostgreSQL locally
# macOS: brew install postgresql
# Ubuntu: sudo apt-get install postgresql
# Windows: Download from https://www.postgresql.org/download/
๐ก Advanced Usage Examples
Memory & Conversation Integration
from personalab import Persona
from personalab.llm import OpenAIClient, AnthropicClient
# Example 1: Educational Tutor with Memory
tutor = Persona(
agent_id="math_tutor",
personality="You are a patient math tutor who tracks student progress.",
use_memory=True, # Remember student profiles and learning history
use_memo=True, # Search previous conversations for context
show_retrieval=True # Show when retrieving relevant past conversations
)
student_id = "student_123"
# First lesson
response1 = tutor.chat("I'm struggling with algebra", user_id=student_id)
response2 = tutor.chat("Can you explain linear equations?", user_id=student_id)
# Later lesson - automatically retrieves relevant context
response3 = tutor.chat("I forgot what we learned about equations", user_id=student_id)
# Update student profile with progress
tutor.endsession(student_id)
# Example 2: Customer Support with Different LLM
support = Persona(
agent_id="support_agent",
llm_client=AnthropicClient(api_key="your-key"), # Using Claude
personality="You are a helpful customer support specialist.",
use_memory=True,
use_memo=True
)
customer_id = "customer_456"
support_response = support.chat("My account is locked", user_id=customer_id)
# Search for similar support tickets
similar_tickets = support.search("account locked", user_id=customer_id, top_k=3)
Direct ConversationManager Usage
from personalab.memo import ConversationManager
# Advanced conversation search and analysis
manager = ConversationManager(
enable_embeddings=True,
embedding_provider="openai" # Use OpenAI embeddings for better quality
)
# Search across all conversations for an agent
results = manager.search_similar_conversations(
agent_id="support_agent",
query="billing issues and refunds",
limit=10,
similarity_threshold=0.75 # Higher threshold for more relevant results
)
for result in results:
print(f"Score: {result['similarity_score']:.3f}")
print(f"User: {result['user_id']}")
print(f"Summary: {result['summary']}")
print("---")
๐๏ธ Architecture
Project Structure
PersonaLab/
โโโ personalab/
โ โโโ __init__.py # Main exports
โ โโโ config.py # Configuration management
โ โโโ llm.py # LLM integration
โ โโโ memory/ # Core memory management module
โ โ โโโ __init__.py # Memory module exports
โ โ โโโ base.py # Core Memory, ProfileMemory, EventMemory, MindMemory
โ โ โโโ manager.py # MemoryClient and conversation processing
โ โ โโโ pipeline.py # MemoryUpdatePipeline and pipeline stages
โ โ โโโ storage.py # MemoryDB and database operations
โ โ โโโ events.py # Event-related utilities
โ โ โโโ profile.py # Profile-related utilities
โ โโโ memo/ # Conversation recording and retrieval module
โ โโโ __init__.py # Memo module exports
โ โโโ models.py # Conversation and Message data models
โ โโโ storage.py # ConversationDB and vector storage
โ โโโ manager.py # ConversationManager and search functionality
โ โโโ embeddings.py # Embedding providers and management
โโโ examples/ # Example scripts and usage demos
โโโ docs/ # Documentation
โโโ tests/ # Test suite
Core Components
Memory Module (personalab.memory)
- Memory: Unified memory class with ProfileMemory, EventMemory, and MindMemory
- MemoryClient: Complete memory lifecycle management
- MemoryUpdatePipeline: Three-stage LLM-driven update process
- MemoryDB: PostgreSQL-based persistent storage
Memo Module (personalab.memo)
- ConversationManager: High-level conversation recording and search
- ConversationDB: Database operations for conversations and vectors
- Conversation/ConversationMessage: Data models with required fields
- EmbeddingProviders: OpenAI, SentenceTransformers, auto-selection
Required Fields for Conversations
All conversations must include these mandatory fields:
agent_id: Unique identifier for the AI agent (required, non-empty)user_id: Unique identifier for the user (required, non-empty)created_at: Timestamp (automatically set when conversation is created)
Embedding Providers
PersonaLab supports multiple embedding providers with automatic fallback:
- OpenAI (Premium):
text-embedding-ada-002(1536 dimensions) - SentenceTransformers (Free): Local models like
all-MiniLM-L6-v2(384 dimensions) - Auto: Automatically selects the best available provider
๐ง Configuration
Environment Variables
# OpenAI (for enhanced embeddings)
export OPENAI_API_KEY="your-openai-api-key"
# Other LLM providers
export ANTHROPIC_API_KEY="your-anthropic-key"
export GOOGLE_AI_API_KEY="your-google-key"
Embedding Provider Configuration
# Use specific embedding provider
manager = ConversationManager(
embedding_provider="openai" # or "sentence-transformers", "auto"
)
# Disable embeddings entirely
manager = ConversationManager(enable_embeddings=False)
Memory Configuration
# Custom persona setup with specific LLM configuration
from personalab.llm import OpenAIClient
custom_llm = OpenAIClient(
api_key="your-key",
model="gpt-4",
temperature=0.3,
max_tokens=2000
)
persona = Persona(
agent_id="custom_assistant",
llm_client=custom_llm,
use_memory=True,
use_memo=True,
show_retrieval=False
)
Search Parameters
# Configure semantic search using Persona
persona = Persona(agent_id="assistant")
user_id = "user_123"
# Search with parameters
results = persona.search(
query="machine learning help",
user_id=user_id,
top_k=10 # Maximum results
)
# Or using ConversationManager directly for more control
manager = ConversationManager()
results = manager.search_similar_conversations(
agent_id="assistant",
query="machine learning help",
limit=10, # Maximum results
similarity_threshold=0.7 # Minimum similarity score (0.0-1.0)
)
๐ Examples
The examples/ directory contains comprehensive usage examples:
memo_simple_example.py: Basic conversation recording and searchconversation_retrieval_example.py: Advanced semantic search demonstrationssimple_embedding_demo.py: Step-by-step embedding workflowconversation_validation_example.py: Required field validation testingquick_start.py: Integration of memory and memo systemsmemo_openai_embedding_example.py: OpenAI embedding optimization
๐ Try the Examples
# Clone the repository to access examples
git clone https://github.com/NevaMind-AI/PersonaLab.git
cd PersonaLab
# Set up environment
cp .env.example .env # Add your API keys
pip install -e .
# Run examples
python examples/quick_start.py
python examples/memo_simple_example.py
๐ Use Cases
Customer Support
# Create support persona
support_persona = Persona(
agent_id="support_bot",
personality="You are a helpful customer support agent.",
use_memory=True,
use_memo=True
)
customer_id = "customer_456"
# Handle customer inquiry (automatically records and retrieves context)
response = support_persona.chat("I'm having login problems", user_id=customer_id)
# Find similar past issues
similar_issues = support_persona.search("login problems", user_id=customer_id, top_k=5)
# End session to update customer profile
support_persona.endsession(customer_id)
Educational Assistants
# Create tutor persona
tutor_persona = Persona(
agent_id="tutor_bot",
personality="You are a patient and encouraging math tutor.",
use_memory=True,
use_memo=True
)
student_id = "student_789"
# Tutoring session (automatically tracks learning progress)
response1 = tutor_persona.chat("I need help with algebra word problems", user_id=student_id)
response2 = tutor_persona.chat("Can you give me another example?", user_id=student_id)
# Retrieve related learning materials from past sessions
related_topics = tutor_persona.search("algebra word problems", user_id=student_id, top_k=5)
# End session to update learning profile
result = tutor_persona.endsession(student_id)
print(f"Learning progress updated: {result}")
Personal AI Assistants
# Create personal assistant
personal_assistant = Persona(
agent_id="personal_ai",
personality="You are a thoughtful personal assistant who remembers important details.",
use_memory=True,
use_memo=True
)
user_id = "user_personal"
# Daily conversation with memory
with personal_assistant.session(user_id):
response1 = personal_assistant.chat("I'm planning a vacation to Japan", user_id=user_id)
response2 = personal_assistant.chat("What should I pack?", user_id=user_id)
# Session automatically ends and updates memory
# Later conversation - retrieves context automatically
response3 = personal_assistant.chat("What were those vacation plans I mentioned?", user_id=user_id)
# Manual context retrieval if needed
context = personal_assistant.search("vacation plans", user_id=user_id, top_k=3)
๐งช Testing
# Run all tests
python -m pytest tests/
# Run specific test files
python -m pytest tests/test_memory.py
python -m pytest tests/test_memo.py
# Run with coverage
python -m pytest --cov=personalab tests/
๐ Documentation
For detailed documentation, see the docs/ directory:
- OpenAI Setup Guide: Configure OpenAI embeddings
- Embedding Providers: Compare embedding options
- API Reference: Detailed method documentation
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- OpenAI for providing excellent embedding models
- SentenceTransformers team for open-source embedding solutions
- Contributors and the AI/ML community for inspiration and feedback
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs/ directory
๐ What's New in v0.1.0
๐ First Official Release! PersonaLab v0.1.0 brings stable, production-ready AI memory management:
โจ Key Features
- ๐๏ธ PostgreSQL-Only Architecture: Removed all SQLite dependencies for production reliability
- ๐ง Enhanced Memory System: Improved profile updates and event tracking
- ๐ฌ Advanced Conversation Search: Semantic search with multiple embedding providers
- ๐ค Multi-LLM Support: OpenAI, Anthropic, Google Gemini, and 8+ other providers
- ๐ฆ PyPI Package: Easy installation with
pip install personalab - ๐ Better Documentation: Comprehensive examples and usage guides
- โก Performance Optimizations: Faster memory updates and conversation retrieval
๐ ๏ธ Technical Improvements
- Python 3.8+ Compatibility: Tested across Python 3.8-3.12
- Automated CI/CD: GitHub Actions for testing and PyPI publishing
- Code Quality: Black, isort, flake8, mypy formatting standards
- Comprehensive Testing: Full test suite with PostgreSQL integration
๐ Migration from Pre-release
If you're upgrading from development versions:
# Remove old development installation
pip uninstall personalab
# Install official release
pip install personalab[all]
๐ Release History
- v0.1.0 (Current) - First official PyPI release with PostgreSQL-only architecture
- Pre-release - Development versions with SQLite support (deprecated)
๐ Links
- PyPI Package: https://pypi.org/project/personalab/
- GitHub Repository: https://github.com/NevaMind-AI/PersonaLab
- Documentation: docs/ directory
- Examples: examples/ directory
PersonaLab - Building the memory foundation for next-generation AI agents ๐ง โจ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file personalab-0.1.3.tar.gz.
File metadata
- Download URL: personalab-0.1.3.tar.gz
- Upload date:
- Size: 61.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a48d885955196c0719d1b37928817dc535a0ecad7d6e3891b3ee91119a486c14
|
|
| MD5 |
9cbb605c0fb8e8a67b8420e8812d58ec
|
|
| BLAKE2b-256 |
456f7b3e24bdb91fa7f1ad5485e5237bf8f631ad0f5c543b66b3c31c7cc28b3a
|
File details
Details for the file personalab-0.1.3-py3-none-any.whl.
File metadata
- Download URL: personalab-0.1.3-py3-none-any.whl
- Upload date:
- Size: 58.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4066ce4fb6f57cf069c3512659ba1e98e880a532c2d4607f5cd640f5e983048a
|
|
| MD5 |
d4e777ff33349c81b2380824aff035c1
|
|
| BLAKE2b-256 |
35cd14bafe8bb01f8d4856a274eaa8c25ab66e6ae29de7b8302c8c9b63a2d189
|