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: List[str]
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
57 58 59 60 61 62 63 |
|
filter(keys=[])
Fetch the memory item.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
37 38 39 40 41 42 43 44 |
|
get_value(key)
Get the value of the field.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
65 66 67 68 69 70 71 72 |
|
get_values(keys)
Get the values of the fields.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
74 75 76 77 78 79 80 |
|
set_value(key, value)
Add a field to the memory item.
Parameters: |
|
---|
Source code in agents/memory/memory.py
46 47 48 49 50 51 52 53 54 55 |
|
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 |
|
to_json()
Convert the memory item to a JSON string.
Returns: |
|
---|
Source code in agents/memory/memory.py
30 31 32 33 34 35 |
|
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: List[MemoryItem]
property
Get the content of the memory.
Returns: |
|
---|
length: int
property
Get the length of the memory.
Returns: |
|
---|
list_content: List[Dict[str, str]]
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
122 123 124 125 126 127 |
|
clear()
Clear the memory.
Source code in agents/memory/memory.py
129 130 131 132 133 |
|
delete_memory_item(step)
Delete a memory item from the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
143 144 145 146 147 148 |
|
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
114 115 116 117 118 119 120 |
|
filter_memory_from_steps(steps)
Filter the memory from the steps.
Parameters: |
|
---|
Returns: |
|
---|
Source code in agents/memory/memory.py
106 107 108 109 110 111 112 |
|
get_latest_item()
Get the latest memory item.
Returns: |
|
---|
Source code in agents/memory/memory.py
160 161 162 163 164 165 166 167 |
|
is_empty()
Check if the memory is empty.
Returns: |
|
---|
Source code in agents/memory/memory.py
185 186 187 188 189 190 |
|
load(content)
Load the data from the memory.
Parameters: |
|
---|
Source code in agents/memory/memory.py
99 100 101 102 103 104 |
|
to_json()
Convert the memory to a JSON string.
Returns: |
|
---|
Source code in agents/memory/memory.py
150 151 152 153 154 155 156 157 158 |
|
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.