What is Memory?
Memory enables your agent to recall past interactions and use them to inform future responses. In Galadriel, memory is implemented through theMemoryStore
class, which provides both short-term and long-term memory capabilities.
- Short-term memory: Stores recent conversations in a simple list structure (enabled by default).
- Long-term memory: Uses vector embeddings to store and retrieve relevant past interactions based on semantic similarity (optional).
How Memory Works
When a user interacts with an agent:- The conversation is stored in short-term memory.
- If short-term memory exceeds its limit (default: 20 interactions), the oldest memory is moved to long-term storage (if enabled).
- When responding to a new query, the agent can access:
- All recent conversations from short-term memory
- Semantically relevant past interactions from long-term memory
Adding Memory to Your Agent
Prerequisites
Make sure you’ve gone through the quick start guide and have the development environment set up.Basic Usage (Short-Term Memory Only)
Short-term memory is enabled by default when using theAgentRuntime
:
Enabling Long-Term Memory
To enable long-term memory, explicitly create aMemoryStore
with OpenAI API credentials and an embedding model:
How Memory Appears in Prompts
When your agent receives a query, memory is automatically integrated into its prompt. Here’s an example:Advanced Memory Features
Saving and Loading Memory
For persistent agents, you can save memory to disk and load it later:Customizing Memory Retrieval (Long-Term Memory Only)
When retrieving memories for a specific query, you can customize:- The number of relevant memories to retrieve (
top_k
) - Filter criteria for memory retrieval
Memory Configuration Options
TheMemoryStore
class accepts several parameters:
Parameter | Description | Default |
---|---|---|
short_term_memory_limit | Maximum number of interactions in short-term memory | 20 |
api_key | OpenAI API key for embeddings (required for long-term memory) | None |
embedding_model | OpenAI embedding model to use | None |
agent_name | Identifier for the agent using this memory store | ”agent” |
Adjusting Short-Term Memory Capacity
Theshort_term_memory_limit
parameter controls how many recent interactions your agent remembers before moving older memories to long-term storage. You can adjust this based on your use case: