Memory
datapizza.memory.memory.Memory
A class for storing the memory of a chat, organized by conversation turns. Each turn can contain multiple blocks (text, function calls, or structured data).
__eq__
Compare two Memory objects based on their content hash. This is more efficient than comparing the full content structure.
add_to_last_turn
Add a block to the most recent turn. Creates a new turn if memory is empty. Args: block (Block): The block to add to the most recent turn.
add_turn
json_dumps
Serialize the memory to JSON.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The JSON representation of the memory. |
json_loads
Deserialize JSON to the memory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_str
|
str
|
The JSON string to deserialize. |
required |
new_turn
Add a new conversation turn.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role
|
ROLE
|
The role of the new turn. Defaults to ROLE.ASSISTANT. |
ASSISTANT
|