Letta Tutorial: Stateful LLM Agents
June 22, 2026 ยท View on GitHub
Build AI agents with persistent memory using the framework formerly known as MemGPT.
Why This Track Matters
Letta is increasingly relevant for developers working with modern AI/ML infrastructure. Build AI agents with persistent memory using the framework formerly known as MemGPT, and this track helps you understand the architecture, key patterns, and production considerations.
This track focuses on:
- Build Stateful Agents that remember everything
- Manage Memory Hierarchies for infinite context
- Create Custom Tools for agent capabilities
- Deploy Agent APIs for production use
๐ฏ What is Letta?
LettaView Repo (formerly MemGPT) is a framework for building stateful LLM agents with persistent memory. Unlike traditional chatbots that forget context, Letta agents maintain long-term memory across conversations.
Key Features
| Feature | Description |
|---|---|
| Persistent Memory | Agents remember across sessions |
| Self-Editing Memory | Agents can update their own memory |
| Infinite Context | Virtual context through memory hierarchy |
| Tool Use | Agents can call external tools |
| Multi-Agent | Coordinate multiple agents |
| REST API | Deploy agents as services |
Mental Model
flowchart TD
A[User Message] --> B[Letta Agent]
B --> C[Core Memory]
B --> D[Archival Memory]
B --> E[Recall Memory]
C --> F[Current Context]
D --> G[Long-term Storage]
E --> H[Conversation History]
F --> I[LLM Processing]
G --> I
H --> I
I --> J[Response + Memory Updates]
J --> C
J --> D
J --> K[User Response]
classDef input fill:#e1f5fe,stroke:#01579b
classDef agent fill:#f3e5f5,stroke:#4a148c
classDef memory fill:#fff3e0,stroke:#ef6c00
classDef output fill:#e8f5e8,stroke:#1b5e20
class A input
class B agent
class C,D,E,F,G,H memory
class I,J,K output
Current Snapshot (auto-updated)
- repository:
letta-ai/letta - stars: about 23.5k
- GitHub release reference:
0.16.8(checked 2026-06-22; release metadata on GitHub)
Chapter Guide
- Chapter 1: Getting Started - Installation, setup, and first agent
- Chapter 2: Memory Architecture - Core, archival, and recall memory
- Chapter 3: Agent Configuration - Personas, system prompts, and models
- Chapter 4: Tool Integration - Adding custom tools and functions
- Chapter 5: Conversation Management - Managing long-running dialogues
- Chapter 6: Multi-Agent Systems - Agent coordination and messaging
- Chapter 7: REST API - Deploying agents as services
- Chapter 8: Production Deployment - Scaling and best practices
What You Will Learn
- Build Stateful Agents that remember everything
- Manage Memory Hierarchies for infinite context
- Create Custom Tools for agent capabilities
- Deploy Agent APIs for production use
- Coordinate Multi-Agent systems
- Persist Conversations across sessions
- Scale Agent Systems for enterprise use
Prerequisites
- Python 3.10+
- API key for your LLM provider
- Understanding of LLM basics
- (Optional) PostgreSQL for persistent storage
Quick Start
# Install Letta
pip install letta
# Start the Letta server
letta server
Creating Your First Agent
from letta import create_client
# Connect to Letta server
client = create_client()
# Create an agent with memory
agent = client.create_agent(
name="assistant",
memory_blocks=[
{
"label": "persona",
"value": "You are a helpful AI assistant with perfect memory."
},
{
"label": "human",
"value": "The user is a software developer interested in AI."
}
],
llm_config={
"model": "gpt-4o",
"context_window": 8192
}
)
# Chat with the agent
response = client.send_message(
agent_id=agent.id,
message="Hi! My name is Alice and I'm working on a machine learning project."
)
print(response.messages[-1].content)
# "Hello Alice! It's great to meet you. I'd love to hear more about
# your machine learning project..."
# Later session - agent remembers!
response = client.send_message(
agent_id=agent.id,
message="What was I working on?"
)
print(response.messages[-1].content)
# "You mentioned you're working on a machine learning project, Alice!"
Memory Architecture
Core Memory
Fast-access memory in the LLM context window:
- Persona Block - Agent's identity and behavior
- Human Block - Information about the user
Archival Memory
Long-term storage for facts and knowledge:
# Agent automatically archives important information
client.send_message(
agent_id=agent.id,
message="I live in San Francisco and work at a startup called TechCo."
)
# Search archival memory
results = client.search_archival_memory(
agent_id=agent.id,
query="Where does the user work?"
)
Recall Memory
Searchable conversation history:
# Search past conversations
results = client.search_recall_memory(
agent_id=agent.id,
query="machine learning",
limit=10
)
Adding Custom Tools
from letta import tool
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city.
Args:
city: Name of the city
Returns:
Current weather description
"""
# Implement weather lookup
return f"Sunny and 72ยฐF in {city}"
@tool
def search_documents(query: str) -> list:
"""Search internal documents.
Args:
query: Search query
Returns:
List of relevant documents
"""
# Implement document search
return ["doc1.pdf", "doc2.pdf"]
# Create agent with tools
agent = client.create_agent(
name="research_assistant",
tools=[get_weather, search_documents]
)
REST API Usage
# Start server
letta server --port 8283
# Create agent via API
curl -X POST http://localhost:8283/v1/agents \
-H "Content-Type: application/json" \
-d '{
"name": "api_agent",
"memory_blocks": [
{"label": "persona", "value": "You are a helpful assistant."}
]
}'
# Send message
curl -X POST http://localhost:8283/v1/agents/{agent_id}/messages \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'
Use Cases
| Use Case | Description |
|---|---|
| Personal Assistant | Long-term memory of user preferences |
| Customer Support | Remember customer history and context |
| Research Agent | Accumulate knowledge over time |
| Tutoring | Track student progress and adapt |
| Healthcare | Maintain patient context safely |
Learning Path
๐ข Beginner Track
- Chapters 1-3: Setup, memory basics, and configuration
- Build a simple stateful assistant
๐ก Intermediate Track
- Chapters 4-6: Tools, conversations, and multi-agent
- Create sophisticated memory-enhanced agents
๐ด Advanced Track
- Chapters 7-8: API deployment and production
- Scale stateful agents for enterprise
Ready to build agents with persistent memory? Let's begin with Chapter 1: Getting Started!
Generated for Awesome Code Docs
Related Tutorials
Navigation & Backlinks
- Start Here: Chapter 1: Getting Started with Letta
- Back to Main Catalog
- Browse A-Z Tutorial Directory
- Search by Intent
- Explore Category Hubs
Full Chapter Map
- Chapter 1: Getting Started with Letta
- Chapter 2: Memory Architecture in Letta
- Chapter 3: Agent Configuration
- Chapter 4: Tool Integration
- Chapter 5: Conversation Management
- Chapter 6: Multi-Agent Systems
- Chapter 7: REST API
- Chapter 8: Production Deployment
Source References
Generated by AI Codebase Knowledge Builder