Short-term Memory
Short-term memory provides session-based conversation history using LangGraph’s Checkpointer system. It automatically preserves conversation context within a session, enabling agents to maintain coherent multi-turn conversations.
Quick Start
Section titled “Quick Start”Basic Configuration
Section titled “Basic Configuration”from langcrew import Crew, Agentfrom langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Enable short-term memorymemory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///memory.db", short_term=ShortTermMemoryConfig(enabled=True))
crew = Crew(agents=[agent], memory=memory_config)Configuration Parameters
Section titled “Configuration Parameters”| Parameter | Type | Description | Default |
|---|---|---|---|
enabled | bool | Enable short-term memory | True |
provider | str | None | Storage provider override (inherits if None) | None |
connection_string | str | None | Connection string override (inherits if None) | None |
Advanced Configuration:
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Override storage provider for short-term memory onlymemory_config = MemoryConfig( provider="sqlite", # Global provider connection_string="sqlite:///global.db", short_term=ShortTermMemoryConfig( enabled=True, provider="postgres", # Override for short-term only connection_string="postgresql://localhost/short_term" ))How It Works
Section titled “How It Works”Short-term memory is managed at the Crew level and automatically propagated to all agents through LangGraph’s checkpointer system.
Crew-Level Management
Section titled “Crew-Level Management”When you configure memory on a Crew, the checkpointer is created and shared across all agents:
crew = Crew( agents=[agent1, agent2], memory=memory_config # Checkpointer managed by Crew)- Crew creates the checkpointer instance
- LangGraph compiles the graph with the checkpointer
- All agents automatically get conversation history
- No need for agents to explicitly manage checkpoints
Thread-based Sessions
Section titled “Thread-based Sessions”Short-term memory uses thread IDs to separate different conversation sessions:
from langcrew import Crew
crew = Crew(agents=[agent], memory=memory_config)
# User A's conversationresult_a = crew.kickoff( inputs={"user_input": "My name is Alice"}, thread_id="user_alice")
# User B's conversation (separate memory)result_b = crew.kickoff( inputs={"user_input": "My name is Bob"}, thread_id="user_bob")
# Alice's follow-up (remembers her name)result_a2 = crew.kickoff( inputs={"user_input": "What's my name?"}, thread_id="user_alice" # Same thread ID)Automatic Context Injection
Section titled “Automatic Context Injection”Short-term memory automatically injects relevant conversation history:
# First messagecrew.kickoff( inputs={"user_input": "I like Italian food"}, thread_id="conversation_1")
# Second message - agent remembers the firstcrew.kickoff( inputs={"user_input": "What kind of food do I like?"}, thread_id="conversation_1" # Same thread = remembers context)# Response: "You mentioned you like Italian food"Use Cases
Section titled “Use Cases”Customer Support
Section titled “Customer Support”Maintain conversation context across a support session:
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Customer support configurationmemory_config = MemoryConfig( provider="postgresql", connection_string="postgresql://user:pass@localhost:5432/support_db", short_term=ShortTermMemoryConfig(enabled=True))
support_agent = Agent( role="Customer Support Agent", goal="Provide helpful support using conversation context", backstory="You remember conversation history to provide contextual help")
crew = Crew(agents=[support_agent], memory=memory_config)
# Support sessioncrew.kickoff( inputs={"user_input": "My order #12345 hasn't arrived"}, thread_id="support_session_789")
crew.kickoff( inputs={"user_input": "When was it supposed to arrive?"}, thread_id="support_session_789" # Remembers order #12345)Educational Tutoring
Section titled “Educational Tutoring”Track learning progress within a tutoring session:
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Educational session configurationmemory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///education.db", short_term=ShortTermMemoryConfig(enabled=True))
tutor_agent = Agent( role="Math Tutor", goal="Teach math concepts building on previous explanations", backstory="You remember concepts covered and student's understanding level")
crew = Crew(agents=[tutor_agent], memory=memory_config)
# Tutoring sessionstudent_id = "student_123"crew.kickoff( inputs={"user_input": "Explain linear equations"}, thread_id=f"student_{student_id}")
crew.kickoff( inputs={"user_input": "Now show me how to solve x + 5 = 10"}, thread_id=f"student_{student_id}")Storage Providers
Section titled “Storage Providers”Short-term memory supports all LangCrew storage providers:
In-Memory (Development)
Section titled “In-Memory (Development)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
memory_config = MemoryConfig( provider="memory", # Fast, no persistence short_term=ShortTermMemoryConfig(enabled=True))SQLite (Single-user/Development)
Section titled “SQLite (Single-user/Development)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
memory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///memory.db", short_term=ShortTermMemoryConfig(enabled=True))PostgreSQL (Production)
Section titled “PostgreSQL (Production)”from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
memory_config = MemoryConfig( provider="postgresql", connection_string="postgresql://user:pass@localhost:5432/memory_db", short_term=ShortTermMemoryConfig(enabled=True))Troubleshooting
Section titled “Troubleshooting”Memory Not Persisting
Section titled “Memory Not Persisting”- Ensure you’re using the same
thread_idacross conversations - Verify database connection and permissions
- Check that checkpointer is properly configured
Context Not Injected
Section titled “Context Not Injected”- Confirm short-term config has
enabled: True - Verify agents are using the same crew instance
Performance Issues
Section titled “Performance Issues”- Use connection pooling for database providers
- Consider SQLite for single-user applications
Next Steps
Section titled “Next Steps”- Long-term Memory - Persistent knowledge storage
- Storage Configuration - Configure storage backends
- Memory Concepts - Understand memory architecture