Memory

class Memory(BaseModel)

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

def get_prompt_template() -> str

Return the current Jinja2 template string.

set_prompt_template

def set_prompt_template(prompt_template: str)

Set a new Jinja2 template string. Validates the template syntax and compatibility with current memory structure.

load

@classmethod
def load(cls, state: dict)

Load memory from dictionary object

compile

def compile() -> str

Generate a string representation of the memory in-context using the Jinja2 template

to_dict

def to_dict()

Convert to dictionary representation

to_flat_dict

def to_flat_dict()

Convert to a dictionary that maps directly from block names to values

list_block_names

def list_block_names() -> List[str]

Return a list of the block names held inside the memory object

get_block

def get_block(name: str) -> Block

Correct way to index into the memory.memory field, returns a Block

get_blocks

def get_blocks() -> List[Block]

Return a list of the blocks held inside the memory object

def link_block(name: str, block: Block, override: Optional[bool] = False)

Link a new block to the memory object

update_block_value

def update_block_value(name: str, value: str)

Update the value of a block

BasicBlockMemory

class BasicBlockMemory(Memory)

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__

def __init__(blocks: List[Block] = [])

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

def core_memory_append(name: str, content: str) -> Optional[str]

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

def core_memory_replace(name: str, old_content: str,
                        new_content: str) -> Optional[str]

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

class ChatMemory(BasicBlockMemory)

ChatMemory initializes a BaseChatMemory with two default blocks, human and persona.

__init__

def __init__(persona: str, human: str, limit: int = 2000)

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.