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')[源代码]

基类: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')[源代码]
property memory_store: BaseMemoryStore

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

返回:

The memory store instance associated with this worker.

返回类型:

BaseMemoryStore

clear()[源代码]

Clear all memory nodes cached, reset the class instance.

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

Add the memories.

参数:
  • 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)[源代码]

Add the memories into '_id_memory_dict' and '_key_id_dict'.

参数:
  • 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][源代码]

Fetch the memories by keys.

参数:

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

返回:

Memories mapped to the key.

返回类型:

List[MemoryNode]

delete_memories(nodes: MemoryNode | List[MemoryNode], key: str | None = None)[源代码]

Delete the memories.

参数:
  • 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[源代码]

Update the memories.

参数:
  • keys (str) -- The memories.

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