Memory
Memory
Base class for Memory management.
This class acts as a high-level facade for memory operations, handling key scoping
(namespacing) and delegating the actual storage logic to an underlying
MemoryStore implementation (e.g., Redis or In-Memory).
Attributes:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
The global prefix used for all keys generated by this instance. |
store |
MemoryStore
|
The backend storage implementation. |
Source code in blue/memories/memory.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
__init__(prefix, properties=None, store=None)
Initialize the Memory instance.
Determines the backing store based on the provided store instance or the
configuration found in properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The base prefix for all keys generated by this instance (e.g., 'PLATFORM:default'). |
required |
properties
|
Dict
|
Configuration dictionary containing connection details
and protocol preferences (e.g., |
None
|
store
|
MemoryStore
|
An explicit, pre-initialized MemoryStore instance.
If provided, |
None
|
Raises:
| Type | Description |
|---|---|
Exception
|
If the 'memory_store.protocol' in |
Source code in blue/memories/memory.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
SessionMemory
Bases: Memory
Specialized Memory management for individual Sessions.
This class extends the base Memory class to provide scoped storage for session-specific
data. It handles the generation of unique keys for each session and provides high-level
methods for storing and retrieving memory entries (e.g., chat logs, state, context)
associated with a specific session ID.
Attributes:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
Inherited from |
store |
MemoryStore
|
Inherited from |
Source code in blue/memories/session_memory.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
__init__(prefix, properties, store=None)
Initialize the SessionMemory instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The base prefix for all keys (e.g., 'PLATFORM'). |
required |
properties
|
Dict
|
Configuration properties passed to the underlying store. |
required |
store
|
MemoryStore
|
Explicit store instance. Defaults to None. |
None
|
Source code in blue/memories/session_memory.py
22 23 24 25 26 27 28 29 30 31 | |
retrieve_session_memory_by_id(session_id, id)
Retrieves a specific memory entry by its unique internal ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session ID context. |
required |
id
|
str
|
The unique entry ID (returned by |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict]
|
Optional[Dict]: The complete memory object if found, None otherwise. |
Source code in blue/memories/session_memory.py
81 82 83 84 85 86 87 88 89 90 91 92 | |
retrieve_session_memory_by_key(session_id, key)
Retrieves a specific memory entry using a custom user-defined key.
This is useful for fetching "singleton" memories like 'summary' or 'last_state' without knowing the generated UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session ID context. |
required |
key
|
str
|
The custom key provided during storage. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict]
|
Optional[Dict]: The complete memory object if found, None otherwise. |
Source code in blue/memories/session_memory.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
retrieve_session_memory_by_similarity(session_id, query_text, limit=3)
Retrieves memory entries based on semantic similarity to a query text.
Note
This method is currently a placeholder and not yet implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session ID context. |
required |
query_text
|
str
|
The text to compare against memory embeddings. |
required |
limit
|
int
|
The maximum number of results to return. Defaults to 3. |
3
|
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List[Dict]: A list of most relevant memory objects (currently None). |
Source code in blue/memories/session_memory.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
retrieve_session_memory_by_time(session_id, start_time, end_time)
Retrieves all memory entries for a session within a specific time window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session ID context. |
required |
start_time
|
float
|
The start timestamp (inclusive, Unix epoch). |
required |
end_time
|
float
|
The end timestamp (inclusive, Unix epoch). |
required |
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List[Dict]: A list of memory objects sorted by time (depending on store implementation). |
Source code in blue/memories/session_memory.py
110 111 112 113 114 115 116 117 118 119 120 121 122 | |
store_session_memory(session_id, agent_id, data, tags=None, key=None)
Stores a new memory entry for a given session.
This method automatically: 1. Generates a unique entry ID (combining UUID and Agent ID). 2. Captures the current timestamp. 3. Wraps the payload in a standard envelope (metadata + data). 4. Indexes the entry by ID, time, and optionally a custom key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session to attach this memory to. |
required |
agent_id
|
str
|
The ID of the agent creating this memory. |
required |
data
|
Any
|
The actual content to store (e.g., a message object, state dict). |
required |
tags
|
List[str]
|
specific tags for categorization. Defaults to None. |
None
|
key
|
str
|
A custom unique key for direct O(1) retrieval later. (e.g., 'latest_summary'). Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique ID generated for the stored memory entry. |
Source code in blue/memories/session_memory.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |