Agent Memory
The Memory
manages the memory of the agent and stores the information required for the agent to interact with the user and applications at every step. Parts of elements in the Memory
will be visible to the agent for decision-making.
MemoryItem
A MemoryItem
is a dataclass
that represents a single step in the agent's memory. The fields of a MemoryItem
is flexible and can be customized based on the requirements of the agent. The MemoryItem
class is defined as follows:
This data class represents a memory item of an agent at one step.
attributes
property
Get the attributes of the memory item.
Returns: |
|
---|
add_values_from_dict(values)
Add fields to the memory item.
Parameters: |
|
---|
Source code in agents/memory/memory.py
66 67 68 69 70 71 72 |
|
filter(keys=[])
Fetch the memory item.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
46 47 48 49 50 51 52 53 |
|
from_dict(data)
Convert the dictionary to a MemoryItem.
Parameters: |
|
---|
Source code in agents/memory/memory.py
31 32 33 34 35 36 37 |
|
get_value(key)
Get the value of the field.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
74 75 76 77 78 79 80 81 |
|
get_values(keys)
Get the values of the fields.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
83 84 85 86 87 88 89 |
|
set_value(key, value)
Add a field to the memory item.
Parameters: |
|
---|
Source code in agents/memory/memory.py
55 56 57 58 59 60 61 62 63 64 |
|
to_dict()
Convert the MemoryItem to a dictionary.
Returns: |
|
---|
Source code in agents/memory/memory.py
19 20 21 22 23 24 25 26 27 28 29 |
|
to_json()
Convert the memory item to a JSON string.
Returns: |
|
---|
Source code in agents/memory/memory.py
39 40 41 42 43 44 |
|
Info
At each step, an instance of MemoryItem
is created and stored in the Memory
to record the information of the agent's interaction with the user and applications.
Memory
The Memory
class is responsible for managing the memory of the agent. It stores a list of MemoryItem
instances that represent the agent's memory at each step. The Memory
class is defined as follows:
This data class represents a memory of an agent.
content
property
Get the content of the memory.
Returns: |
|
---|
length
property
Get the length of the memory.
Returns: |
|
---|
list_content
property
List the content of the memory.
Returns: |
|
---|
add_memory_item(memory_item)
Add a memory item to the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
131 132 133 134 135 136 |
|
clear()
Clear the memory.
Source code in agents/memory/memory.py
138 139 140 141 142 |
|
delete_memory_item(step)
Delete a memory item from the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
152 153 154 155 156 157 |
|
filter_memory_from_keys(keys)
Filter the memory from the keys. If an item does not have the key, the key will be ignored.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
123 124 125 126 127 128 129 |
|
filter_memory_from_steps(steps)
Filter the memory from the steps.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
115 116 117 118 119 120 121 |
|
from_list_of_dicts(data)
Convert the list of dictionaries to the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
176 177 178 179 180 181 182 183 184 185 |
|
get_latest_item()
Get the latest memory item.
Returns: |
|
---|
Source code in agents/memory/memory.py
187 188 189 190 191 192 193 194 |
|
is_empty()
Check if the memory is empty.
Returns: |
|
---|
Source code in agents/memory/memory.py
212 213 214 215 216 217 |
|
load(content)
Load the data from the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
108 109 110 111 112 113 |
|
to_json()
Convert the memory to a JSON string.
Returns: |
|
---|
Source code in agents/memory/memory.py
159 160 161 162 163 164 165 166 167 |
|
to_list_of_dicts()
Convert the memory to a list of dictionaries.
Returns: |
|
---|
Source code in agents/memory/memory.py
169 170 171 172 173 174 |
|
Info
Each agent has its own Memory
instance to store their information.
Info
Not all information in the Memory
are provided to the agent for decision-making. The agent can access parts of the memory based on the requirements of the agent's logic.