Memory
Memory
Represents the in-context memory of the agent. This includes both the Block
objects (labelled by sections), as well as tools to edit the blocks.
Attributes:
memory
Dict[str, Block] - Mapping from memory block section to memory block.
get_prompt_template
Return the current Jinja2 template string.
set_prompt_template
Set a new Jinja2 template string. Validates the template syntax and compatibility with current memory structure.
load
Load memory from dictionary object
compile
Generate a string representation of the memory in-context using the Jinja2 template
to_dict
Convert to dictionary representation
to_flat_dict
Convert to a dictionary that maps directly from block names to values
list_block_names
Return a list of the block names held inside the memory object
get_block
Correct way to index into the memory.memory field, returns a Block
get_blocks
Return a list of the blocks held inside the memory object
link_block
Link a new block to the memory object
update_block_value
Update the value of a block
BasicBlockMemory
BasicBlockMemory is a basic implemention of the Memory class, which takes in a list of blocks and links them to the memory object. These are editable by the agent via the core memory functions.
Attributes:
memory
Dict[str, Block] - Mapping from memory block section to memory block.
Methods:
core_memory_append
- Append to the contents of core memory.core_memory_replace
- Replace the contents of core memory.
__init__
Initialize the BasicBlockMemory object with a list of pre-defined blocks.
Arguments:
blocks
List[Block] - List of blocks to be linked to the memory object.
core_memory_append
Append to the contents of core memory.
Arguments:
name
str - Section of the memory to be edited (persona or human).content
str - Content to write to the memory. All unicode (including emojis) are supported.
Returns:
Optional[str]
- None is always returned as this function does not produce a response.
core_memory_replace
Replace the contents of core memory. To delete memories, use an empty string for new_content.
Arguments:
name
str - Section of the memory to be edited (persona or human).old_content
str - String to replace. Must be an exact match.new_content
str - Content to write to the memory. All unicode (including emojis) are supported.
Returns:
Optional[str]
- None is always returned as this function does not produce a response.
ChatMemory
ChatMemory initializes a BaseChatMemory with two default blocks, human
and persona
.
__init__
Initialize the ChatMemory object with a persona and human string.
Arguments:
persona
str - The starter value for the persona block.human
str - The starter value for the human block.limit
int - The character limit for each block.