Skip to content

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.

from langcrew import Crew, Agent
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Enable short-term memory
memory_config = MemoryConfig(
provider="sqlite",
connection_string="sqlite:///memory.db",
short_term=ShortTermMemoryConfig(enabled=True)
)
crew = Crew(agents=[agent], memory=memory_config)
ParameterTypeDescriptionDefault
enabledboolEnable short-term memoryTrue
providerstr | NoneStorage provider override (inherits if None)None
connection_stringstr | NoneConnection string override (inherits if None)None

Advanced Configuration:

from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Override storage provider for short-term memory only
memory_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"
)
)

Short-term memory is managed at the Crew level and automatically propagated to all agents through LangGraph’s checkpointer system.

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

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 conversation
result_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
)

Short-term memory automatically injects relevant conversation history:

# First message
crew.kickoff(
inputs={"user_input": "I like Italian food"},
thread_id="conversation_1"
)
# Second message - agent remembers the first
crew.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"

Maintain conversation context across a support session:

from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Customer support configuration
memory_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 session
crew.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
)

Track learning progress within a tutoring session:

from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
# Educational session configuration
memory_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 session
student_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}"
)

Short-term memory supports all LangCrew storage providers:

from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
memory_config = MemoryConfig(
provider="memory", # Fast, no persistence
short_term=ShortTermMemoryConfig(enabled=True)
)
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig
memory_config = MemoryConfig(
provider="sqlite",
connection_string="sqlite:///memory.db",
short_term=ShortTermMemoryConfig(enabled=True)
)
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)
)
  • Ensure you’re using the same thread_id across conversations
  • Verify database connection and permissions
  • Check that checkpointer is properly configured
  • Confirm short-term config has enabled: True
  • Verify agents are using the same crew instance
  • Use connection pooling for database providers
  • Consider SQLite for single-user applications