memoryscope.core.worker.memory_manager

class memoryscope.core.worker.memory_manager.MemoryManager(memoryscope_context: ~memoryscope.core.utils.singleton.singleton.<locals>._singleton, workerflow_name: str = 'default_worker')[source]

Bases: object

The MemoryHandler class manages memory nodes with memory store.

__init__(memoryscope_context: ~memoryscope.core.utils.singleton.singleton.<locals>._singleton, workerflow_name: str = 'default_worker')[source]
property memory_store: BaseMemoryStore

Property to access the memory store. If not initialized, it fetches the memory store from the global context.

Returns:

The memory store instance associated with this worker.

Return type:

BaseMemoryStore

clear()[source]

Clear all memory nodes cached, reset the class instance.

add_memories(key: str, nodes: MemoryNode | List[MemoryNode], log_repeat: bool = True)[source]

Add the memories.

Parameters:
  • key (str) – The key mapping to memory nodes.

  • nodes (List[MemoryNode]) – A single memory node or a list of memory nodes to be updated.

  • log_repeat (bool) – Log duplicated memory node or not.

set_memories(key: str, nodes: MemoryNode | List[MemoryNode], log_repeat: bool = True)[source]

Add the memories into ‘_id_memory_dict’ and ‘_key_id_dict’.

Parameters:
  • key (str) – The key mapping to memory nodes.

  • nodes (List[MemoryNode]) – A single memory node or a list of memory nodes to be updated.

  • log_repeat – if log_repeat=True, print log info

get_memories(keys: str | List[str]) List[MemoryNode][source]

Fetch the memories by keys.

Parameters:

keys (str | List[str]) – The key mapping to memory nodes.

Returns:

Memories mapped to the key.

Return type:

List[MemoryNode]

delete_memories(nodes: MemoryNode | List[MemoryNode], key: str | None = None)[source]

Delete the memories.

Parameters:
  • key (str) – The key mapping to memory nodes.

  • nodes (List[MemoryNode]) – A single memory node or a list of memory nodes to be deleted.

update_memories(keys: str = '', nodes: MemoryNode | List[MemoryNode] | None = None) dict[source]

Update the memories.

Parameters:
  • keys (str) – The memories.

  • nodes (List[MemoryNode]) – A single memory node or a list of memory nodes to be updated.