Skip to main content

ChatHistoryMemory

An agent memory wrapper of :obj:ChatHistoryBlock. Parameters:
  • context_creator (BaseContextCreator): A model context creator.
  • storage (BaseKeyValueStorage, optional): A storage backend for storing chat history. If None, an :obj:InMemoryKeyValueStorage will be used. (default: :obj:None)
  • window_size (int, optional): The number of recent chat messages to retrieve. If not provided, the entire chat history will be retrieved. (default: :obj:None)
  • agent_id (str, optional): The ID of the agent associated with the chat history.

init

agent_id

agent_id

retrieve

write_records

get_context_creator

clear

clean_tool_calls

Removes tool call messages from memory. This method removes all FUNCTION/TOOL role messages and any ASSISTANT messages that contain tool_calls in their meta_dict to save token usage.

pop_records

Removes the most recent records from chat history memory.

remove_records_by_indices

Removes records at specified indices from chat history memory.

VectorDBMemory

An agent memory wrapper of :obj:VectorDBBlock. This memory queries messages stored in the vector database. Notice that the most recent messages will not be added to the context. Parameters:
  • context_creator (BaseContextCreator): A model context creator.
  • storage (BaseVectorStorage, optional): A vector storage storage. If None, an :obj:QdrantStorage will be used. (default: :obj:None)
  • retrieve_limit (int, optional): The maximum number of messages to be added into the context. (default: :obj:3)
  • agent_id (str, optional): The ID of the agent associated with the messages stored in the vector database.

init

agent_id

agent_id

retrieve

write_records

get_context_creator

clear

Removes all records from the vector database memory.

pop_records

Rolling back is unsupported for vector database memory.

remove_records_by_indices

Removing by indices is unsupported for vector database memory.

LongtermAgentMemory

An implementation of the :obj:AgentMemory abstract base class for augmenting ChatHistoryMemory with VectorDBMemory. Parameters:
  • context_creator (BaseContextCreator): A model context creator.
  • chat_history_block (Optional[ChatHistoryBlock], optional): A chat history block. If None, a :obj:ChatHistoryBlock will be used. (default: :obj:None)
  • vector_db_block (Optional[VectorDBBlock], optional): A vector database block. If None, a :obj:VectorDBBlock will be used. (default: :obj:None)
  • retrieve_limit (int, optional): The maximum number of messages to be added into the context. (default: :obj:3)
  • agent_id (str, optional): The ID of the agent associated with the chat history and the messages stored in the vector database.

init

agent_id

agent_id

get_context_creator

Returns: BaseContextCreator: The context creator used by the memory.

retrieve

Returns: List[ContextRecord]: A list of context records retrieved from both the chat history and the vector database.

write_records

Converts the provided chat messages into vector representations and writes them to the vector database. Parameters:
  • records (List[MemoryRecord]): Messages to be added to the vector database.

clear

Removes all records from the memory.

pop_records

Removes recent chat history records while leaving vector memory.

remove_records_by_indices

Removes records at specified indices from chat history.