Getting Started
Get up and running with LangCrew Memory in just a few minutes. This guide covers basic setup and common usage patterns.
Installation
Section titled “Installation”Install LangCrew with memory support:
# Install LangCrewuv add langcrewBasic Usage
Section titled “Basic Usage”1. Simple Memory Setup
Section titled “1. Simple Memory Setup”from langcrew import Agent, Crew
# Create memory configuration - just enable it!memory_config = True # Uses default settings with all memory types enabled
# Create agent with memoryagent = Agent( role="Memory Assistant", goal="Remember and use information from our conversations", backstory="You are an AI assistant with excellent memory capabilities")
# Create crew with shared memorycrew = Crew( agents=[agent], memory=memory_config)2. Run Your First Memory-Enabled Conversation
Section titled “2. Run Your First Memory-Enabled Conversation”# First conversationresult1 = crew.kickoff( inputs={"user_input": "My name is Alice and I love pizza"}, thread_id="conversation_1")
# Later conversation - agent remembers Aliceresult2 = crew.kickoff( inputs={"user_input": "What food do I like?"}, thread_id="conversation_1" # Same thread ID)
print(result2) # Agent will remember Alice likes pizza3. Persistent Memory with SQLite
Section titled “3. Persistent Memory with SQLite”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig
# Persistent memory configurationmemory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///my_memory.db", short_term=ShortTermMemoryConfig(enabled=True), long_term=LongTermMemoryConfig(enabled=True))
crew = Crew(agents=[agent], memory=memory_config)
# Memory persists across program restartsresult = crew.kickoff( inputs={"user_input": "Remember that I work at TechCorp"}, thread_id="user_alice")Memory Types in Action
Section titled “Memory Types in Action”Short-term Memory
Section titled “Short-term Memory”Remembers recent conversation history within a session:
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Configure short-term memorymemory_config = MemoryConfig( short_term=ShortTermMemoryConfig(enabled=True))
# Agent will remember context from recent messagescrew = Crew(agents=[agent], memory=memory_config)Long-term Memory
Section titled “Long-term Memory”Stores important knowledge across sessions:
from langcrew.memory import LongTermMemoryConfig
# Configure long-term memorymemory_config = MemoryConfig( long_term=LongTermMemoryConfig( enabled=True, app_id="my-app" # RECOMMENDED for production ))
# Agent learns and remembers important factscrew = Crew(agents=[agent], memory=memory_config)Configuration Examples
Section titled “Configuration Examples”Development Setup (In-Memory)
Section titled “Development Setup (In-Memory)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig
memory_config = MemoryConfig( provider="memory", # Fast, no persistence short_term=ShortTermMemoryConfig(enabled=True), long_term=LongTermMemoryConfig(enabled=True))Production Setup (PostgreSQL)
Section titled “Production Setup (PostgreSQL)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig
memory_config = MemoryConfig( provider="postgresql", connection_string="postgresql://user:pass@localhost:5432/memory_db", short_term=ShortTermMemoryConfig(enabled=True), long_term=LongTermMemoryConfig(enabled=True))Local Development (SQLite)
Section titled “Local Development (SQLite)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig
memory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///development.db", short_term=ShortTermMemoryConfig(enabled=True), long_term=LongTermMemoryConfig(enabled=True))Common Patterns
Section titled “Common Patterns”Customer Service Agent
Section titled “Customer Service Agent”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Memory-enabled customer servicememory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///customer_service.db", short_term=ShortTermMemoryConfig(enabled=True))
service_agent = Agent( role="Customer Service Representative", goal="Provide personalized customer support", backstory="You remember customer history and preferences")
crew = Crew(agents=[service_agent], memory=memory_config)
# Each customer gets their own threadresult = crew.kickoff( inputs={"user_input": "I need help with my order"}, thread_id=f"customer_{customer_id}")Learning Assistant
Section titled “Learning Assistant”from langcrew.memory import LongTermMemoryConfig
# Memory-enabled learning assistantmemory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///learning.db", long_term=LongTermMemoryConfig( enabled=True, app_id="learning-assistant" ))
tutor = Agent( role="Personal Tutor", goal="Adapt teaching based on student progress", backstory="You remember what students have learned and their difficulties")
crew = Crew(agents=[tutor], memory=memory_config)Troubleshooting
Section titled “Troubleshooting”Memory Not Persisting
Section titled “Memory Not Persisting”- Check your
connection_stringformat - Ensure database permissions are correct
- Verify the database file/connection is accessible
High Memory Usage
Section titled “High Memory Usage”- Use connection pooling for database providers
- Consider using SQLite/PostgreSQL instead of in-memory
Slow Performance
Section titled “Slow Performance”- Use PostgreSQL for production workloads
- Enable connection pooling for database providers
- Consider memory provider for development/testing