Note of 7 November 2026: the stack described here is not today's
Where this article speaks in the first person about the VPS, the portfolio or the ml-service running Ollama, it describes the configuration the site had until the 23 October 2026 deploy. Since that date text generation goes through OpenRouter, free plan, with data_collection: "deny" on every request; embeddings and the vector index stay on the VPS. Ollama is not in service on the site, and generation is not on-prem. Figures and hardware details quoted here belong to that configuration and have not been re-measured. A move to local models on the VPS has been decided (7 November 2026) but is not active yet.
Letta (ex-MemGPT): persistent memory for agents
Letta is an open-source framework enabling AI agents with persistent and reliable memory. Discover how to build agents capable of remembering conversations, maintaining state, and interacting statelessly without losing context — essential for deploying self-hosted agentic platforms.
What is Letta and why persistent memory matters
Traditional AI agents suffer from a fundamental problem: they forget. A large-scale LLM processes context within its token context window, but once the conversational window closes, the model has no memory of the past. For mission-critical applications — customer support systems, research assistants, business automation — this loss of state is unacceptable.
Letta (formerly known as MemGPT) solves this problem by implementing a persistent memory layer that works like virtual RAM for the agent. Instead of passing the entire conversation history to the model, Letta manages structured memory (core memory, archival memory, message history) that the agent can query and update dynamically during execution.
This approach enables:
- Long-term conversations without context loss — the agent remembers past interactions indefinitely
- Reduced token spending — no need to resend entire history; Letta retrieves only relevant data
- Reliable and predictable agents — behavior is consistent over time because state is persistent
- Easy integration with self-hosted systems — Letta runs on private infrastructure without dependency on external cloud APIs
Letta architecture: core memory and archival memory
Letta implements a three-tier memory architecture:
1. Core Memory (Short-term Memory)
Core memory is the agent's "notepad". It's small, fast, and always available in the LLM's context. It contains critical information like the user's name, recurring preferences, system instructions. Letta automatically passes core memory to the LLM prompt on each request.
{
"human": {
"name": "Alice",
"preferences": "prefers concise responses",
"role": "software engineer"
},
"persona": {
"name": "Cortex",
"role": "AI Assistant",
"instructions": "You are a technical assistant specialized in software"
}
}
2. Archival Memory (Long-term Memory)
Archival memory is the agent's "hard drive". It stores the full transcript of past conversations, documents, contextual data. Letta indexes this memory so the agent can search for relevant information without reading the entire database.
{
"type": "archival_memory",
"messages": [
{
"timestamp": "2026-06-16T10:23:00Z",
"user": "Alice",
"content": "I have a bug in React with performance issues"
},
{
"timestamp": "2026-06-16T10:24:00Z",
"assistant": "Likely an unnecessary re-render. Should we use React Profiler?",
"tokens_used": 87
}
]
}
3. Message History (Conversational Window)
The message history is the current context window that Letta sends to the LLM. It contains the last N messages of the current conversation, dynamically truncated to respect the LLM's token limit.
Setup and installation of self-hosted Letta
Letta is open-source and can run completely self-hosted on a VPS. Let's start with basic installation using Docker:
# Clone the Letta repository
git clone https://github.com/letta-ai/letta.git
cd letta
# Build the Docker image
docker build -t letta:latest .
# Start the container with persistent volume for memory
docker run -d \
--name letta-agent \
-p 8080:8080 \
-v letta-data:/root/.letta \
-e LETTA_DB_TYPE=postgresql \
-e DATABASE_URL=postgresql://user:password@postgres:5432/letta \
letta:latest
If you prefer native installation (without Docker):
# Install via pip (requires Python 3.9+)
pip install letta-ai
# Initialize the database (PostgreSQL or SQLite)
letta db init
# Start the Letta server
letta server start --host 0.0.0.0 --port 8080
Creating an agent with persistent memory
Once Letta is running, creating an agent is straightforward via REST API or Python SDK:
#!/usr/bin/env python3
from letta.client import LocalClient
from letta.schemas.agent import AgentState
# Connect to the local Letta server
client = LocalClient()
# Create a new agent
agent = client.create_agent(
name="Research Assistant",
persona="You are an expert research assistant in AI",
human_name="Alice",
model="llama3.1:8b", # Use a self-hosted Ollama model
embedding_model="sentence-transformers/all-MiniLM-L6-v2",
memory_type="hybrid" # core + archival
)
print(f"Agent created: {agent.id}")
# Access the agent's memory
core_memory = agent.core_memory
print(f"Core memory: {core_memory}")
Example: conversation with persistent state
Suppose Alice interacts with the agent across multiple sessions. Letta maintains memory between sessions:
# Session 1
response1 = agent.send_message(
message="My name is Alice and I work as a software engineer",
user_id="user_alice"
)
print(response1) # Agent responds
# The agent automatically updates core memory
# { "human": { "name": "Alice", "role": "software engineer" } }
# Session 2 (hours later)
response2 = agent.send_message(
message="What was my role?",
user_id="user_alice"
)
# Output: "You are Alice, a software engineer. I remember perfectly."
# The agent retrieves info from persistent core memory
Memory management: update and query
Letta provides explicit APIs for updating and querying memory. This is crucial for maintaining coherent state:
Updating core memory
# Update user profile in core memory
agent.core_memory.update(
human_name="Alice Chen",
role="Staff Engineer at TechCorp",
preferences="detailed technical responses, code examples"
)
# The next request will include this info in the prompt
Searching archival memory
# Search previous discussions on a topic
results = agent.archival_memory.search(
query="bug in React performance",
top_k=5 # return the 5 most relevant results
)
for result in results:
print(f"Date: {result['timestamp']}, Content: {result['content']}")
# Output:
# Date: 2026-06-16T10:23:00Z, Content: I have a bug in React with performance issues
# Date: 2026-06-15T14:12:00Z, Content: React profiler shows unexpected re-renders
Integration with Ollama for self-hosted LLM
One of Letta's key advantages is compatibility with open-source LLMs. Integrate Ollama (one of the most widely used on-prem providers) as a backend:
#!/usr/bin/env python3
from letta.models import ModelConfig
from letta.client import LocalClient
# Configure Letta to use Ollama
client = LocalClient()
# Create an agent using Llama 3.1 via Ollama
agent = client.create_agent(
name="Technical Advisor",
model="ollama/llama3.1:8b",
model_endpoint="http://localhost:11434", # Local Ollama endpoint
temperature=0.7,
top_p=0.9
)
# Throughout the session, the agent calls Ollama without depending on cloud services
response = agent.send_message("Explain how Bitcoin consensus works")
print(response)
This setup ensures all interactions remain within your private infrastructure. No data is sent to external cloud services.
Advanced patterns: custom tools and tool calling
Letta supports tool calling — the agent can invoke external functions to extend its capabilities:
#!/usr/bin/env python3
from letta.client import LocalClient
from letta.schemas.tools import Tool, ToolParameter
client = LocalClient()
# Define a custom tool
search_tool = Tool(
name="search_codebase",
description="Search files and functions in the company codebase",
parameters=[
ToolParameter(name="query", type="string", required=True),
ToolParameter(name="file_type", type="string", required=False)
]
)
# Register the tool
client.add_tool(search_tool)
# Now the agent can invoke this tool when needed
agent = client.create_agent(
name="Code Reviewer",
tools=[search_tool]
)
# The agent will use the tool autonomously during conversation
response = agent.send_message(
"Where in the codebase do we implement IBAN validation?"
)
# The agent invokes search_codebase(query="IBAN validation")
# and integrates the result into the response
Scaling: persistent storage and databases
For production, Letta should use a robust database for archival memory. PostgreSQL is the recommended option:
# docker-compose.yml for Letta + PostgreSQL
version: '3.8'
services:
letta:
image: letta:latest
ports:
- "8080:8080"
environment:
LETTA_DB_TYPE: postgresql
DATABASE_URL: postgresql://letta:password@postgres:5432/letta_db
OLLAMA_ENDPOINT: http://ollama:11434
depends_on:
- postgres
- ollama
volumes:
- letta-data:/root/.letta
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: letta
POSTGRES_PASSWORD: password
POSTGRES_DB: letta_db
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
ollama:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
volumes:
postgres-data:
letta-data:
ollama-data:
With this setup, agent memory is persistent, scalable, and production-ready on VPS or Kubernetes.
Monitoring and debugging
Letta provides tools to monitor memory usage and agent behavior:
# Access agent statistics
stats = agent.get_stats()
print(f"Total messages: {stats['total_messages']}")
print(f"Tokens used: {stats['total_tokens']}")
print(f"Core memory size: {stats['core_memory_size_tokens']}")
print(f"Archival memory size: {stats['archival_memory_size_tokens']}")
# Export memory for backup
memory_dump = agent.export_memory()
with open(f"agent_{agent.id}_memory.json", "w") as f:
json.dump(memory_dump, f, indent=2)
Real-world use cases
Support chatbot with persistent history
A customer support chatbot can remember all past interactions with a customer, providing contextual responses and avoiding repetition of issues.
Research assistant for data analysts
An agent assisting data analysts can maintain memory of previous queries, formatting preferences, and topics they're working on.
Automation agent for DevOps
An automation agent can remember infrastructure state, previous actions taken, and error patterns, improving remediation decisions.
Limitations and trade-offs
- Memory search latency — searching archival memory requires a database query, adding latency versus a simple context window
- Embedding overhead — Letta uses embeddings for semantic search, requiring additional computation
- Manual privacy management — data stays on your server, but you must handle backups, encryption, and compliance
- Storage costs — indefinite memory has a cost, especially for long conversations or many parallel agents
Frequently asked questions
Is Letta truly open-source?
Yes, Letta is available on GitHub under Apache 2.0 license. You can self-host completely without commercial restrictions.
Which LLM should I use with Letta?
Letta supports any LLM with standard REST API interface. We recommend Llama 3.1 or Mistral on Ollama for optimal balance between performance and self-hosted costs.
How much does persistent memory cost to operate?
Costs are primarily storage and embedding computation. With PostgreSQL on a standard VPS (€10-20/month), you can manage millions of messages for a handful of agents.
Can I migrate a Letta agent to another infrastructure?
Yes. Letta supports memory export/import in JSON. You can backup memory with agent.export_memory() and restore on another instance.
Is Letta suitable for multi-tenant environments?
Yes, with proper isolation. Letta supports agent namespacing and granular access controls. For robust multi-tenant, I recommend dedicated architecture per tenant.
Commenti
Caricamento commenti...
Sign in to comment