Memory-enabled AI assistant with local LLM support
Project description
๐ง Mem-Agent: Memory-Enabled Mini Assistant
A local AI assistant that remembers user interactions and responds with context awareness using a lightweight 4-billion parameter LLM.
Quick Start โข Features โข Documentation โข Examples
๐ฏ Why Mem-Agent?
Most Large Language Models (LLMs) treat every conversation as "new" and don't remember past interactions. Mem-Agent uses a small locally-running model to:
- โ Remember user history - Separate memory for each customer/user
- โ Context awareness - Responds based on previous conversations
- โ Fully local - No internet connection required
- โ Lightweight & fast - Only 2.5 GB model size
- โ Easy integration - Get started with 3 lines of code
๐ Quick Start
1. Install Ollama
# Windows/Mac/Linux: https://ollama.ai/download
curl https://ollama.ai/install.sh | sh
# Start the service
ollama serve
2. Download Model
ollama pull granite4:tiny-h
3. Use Mem-Agent
from mem_llm import MemAgent
# Create agent
agent = MemAgent(model="granite4:tiny-h")
# System check
status = agent.check_setup()
if status['status'] == 'ready':
print("โ
System ready!")
else:
print("โ Error:", status)
# Set user
agent.set_user("user123")
# First conversation
response = agent.chat("Hello, my name is Ali")
print(response)
# Second conversation - It remembers me!
response = agent.chat("Do you remember my name?")
print(response)
๐ Example Scripts
1. Simple Test
python examples/example_simple.py
2. Customer Service Simulation
python examples/example_customer_service.py
๐๏ธ Project Structure
Memory LLM/
โโโ memory_llm/ # Main package
โ โโโ __init__.py # Package initialization
โ โโโ mem_agent.py # Main assistant class
โ โโโ memory_manager.py # Memory management
โ โโโ memory_db.py # SQL database support
โ โโโ llm_client.py # Ollama integration
โ โโโ memory_tools.py # User tools
โ โโโ knowledge_loader.py # Knowledge base loader
โ โโโ prompt_templates.py # Prompt templates
โ โโโ config_manager.py # Configuration manager
โโโ examples/ # Example scripts
โโโ tests/ # Test files
โโโ setup.py # Installation script
โโโ requirements.txt # Dependencies
โโโ README.md # This file
๐ง API Usage
MemAgent Class
from mem_llm import MemAgent
agent = MemAgent(
model="granite4:tiny-h", # Ollama model name
memory_dir="memories", # Memory directory
ollama_url="http://localhost:11434" # Ollama API URL
)
Basic Methods
# Set user
agent.set_user("user_id")
# Chat
response = agent.chat(
message="Hello",
user_id="optional_user_id", # If set_user not used
metadata={"key": "value"} # Additional information
)
# Get memory summary
summary = agent.memory_manager.get_summary("user_id")
# Search in history
results = agent.search_user_history("keyword", "user_id")
# Update profile
agent.update_user_info({
"name": "Ali",
"preferences": {"language": "en"}
})
# Get statistics
stats = agent.get_statistics()
# Export memory
json_data = agent.export_memory("user_id")
# Clear memory (WARNING!)
agent.clear_user_memory("user_id", confirm=True)
MemoryManager Class
from mem_llm import MemoryManager
memory = MemoryManager(memory_dir="memories")
# Load memory
data = memory.load_memory("user_id")
# Add interaction
memory.add_interaction(
user_id="user_id",
user_message="Hello",
bot_response="Hello! How can I help you?",
metadata={"timestamp": "2025-01-13"}
)
# Get recent conversations
recent = memory.get_recent_conversations("user_id", limit=5)
# Search
results = memory.search_memory("user_id", "order")
OllamaClient Class
from mem_llm import OllamaClient
client = OllamaClient(model="granite4:tiny-h")
# Simple generation
response = client.generate("Hello world!")
# Chat format
response = client.chat([
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello"}
])
# Connection check
is_ready = client.check_connection()
# Model list
models = client.list_models()
๐ก Usage Scenarios
1. Customer Service Bot
- Remembers customer history
- Knows previous issues
- Makes personalized recommendations
2. Personal Assistant
- Tracks daily activities
- Learns preferences
- Makes reminders
3. Education Assistant
- Tracks student progress
- Adjusts difficulty level
- Remembers past mistakes
4. Support Ticket System
- Stores ticket history
- Finds related old tickets
- Provides solution suggestions
๐ Memory Format
Memories are stored in JSON format:
{
"conversations": [
{
"timestamp": "2025-01-13T10:30:00",
"user_message": "Hello",
"bot_response": "Hello! How can I help you?",
"metadata": {
"topic": "greeting"
}
}
],
"profile": {
"user_id": "user123",
"first_seen": "2025-01-13T10:30:00",
"preferences": {},
"summary": {}
},
"last_updated": "2025-01-13T10:35:00"
}
๐ Privacy and Security
- โ Works completely locally (no internet connection required)
- โ Data stored on your computer
- โ No data sent to third-party services
- โ Memories in JSON format, easily deletable
๐ ๏ธ Development
Test Mode
# Simple chat without memory (for testing)
response = agent.simple_chat("Test message")
Using Your Own Model
# Different Ollama model
agent = MemAgent(model="llama2:7b")
# Or another LLM API
# Customize llm_client.py file
๐ Troubleshooting
Ollama Connection Error
# Start Ollama service
ollama serve
# Port check
netstat -an | findstr "11434"
Model Not Found
# Check model list
ollama list
# Download model
ollama pull granite4:tiny-h
Memory Issues
# Check memory directory
import os
os.path.exists("memories")
# List memory files
os.listdir("memories")
๐ Performance
- Model Size: ~2.5 GB
- Response Time: ~1-3 seconds (depends on CPU)
- Memory Usage: ~4-6 GB RAM
- Disk Usage: ~10-50 KB per user
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'feat: Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
๐ License
MIT License - See LICENSE file for details.
๐ Acknowledgments
๐ Contact
You can open an issue for your questions.
Note: This project is for educational and research purposes. Please perform comprehensive testing before using in production environment.
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 mem_llm-1.0.1.tar.gz.
File metadata
- Download URL: mem_llm-1.0.1.tar.gz
- Upload date:
- Size: 43.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae34978fcb75a246c828713a03170009d05091b8a0554a2101b2e74c12067db2
|
|
| MD5 |
43ddf30addba53cdf63a0ecdeafd2ed4
|
|
| BLAKE2b-256 |
570373922abd50f7718b3a622739d9bdc27e028e2122bdca1c02e8cc0ed25702
|
File details
Details for the file mem_llm-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mem_llm-1.0.1-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
940e3a26343564c3ab68af2955ec3fae2f1d788a09feb56f6284b920b0cb281b
|
|
| MD5 |
9f33258a3e33e24c05b2a46d86adf6d1
|
|
| BLAKE2b-256 |
a0ce51b3e7332aade91231335f89d5f9a611b9373be1998543ef68d633b03d9b
|