MCPcopy Create free account
hub / github.com/MemTensor/MemOS / add

Method add

src/memos/mem_os/core.py:684–923  ·  view source on GitHub ↗

Add textual memories to a MemCube. Args: messages (Union[MessageList, str]): The path to a document or a list of messages. memory_content (str, optional): The content of the memory to add. doc_path (str, optional): The path to the document associ

(
        self,
        messages: MessageList | None = None,
        memory_content: str | None = None,
        doc_path: str | None = None,
        mem_cube_id: str | None = None,
        user_id: str | None = None,
        session_id: str | None = None,
        task_id: str | None = None,  # New: Add task_id parameter
        **kwargs,
    )

Source from the content-addressed store, hash-verified

682 return result
683
684 def add(
685 self,
686 messages: MessageList | None = None,
687 memory_content: str | None = None,
688 doc_path: str | None = None,
689 mem_cube_id: str | None = None,
690 user_id: str | None = None,
691 session_id: str | None = None,
692 task_id: str | None = None, # New: Add task_id parameter
693 **kwargs,
694 ) -> None:
695 """
696 Add textual memories to a MemCube.
697
698 Args:
699 messages (Union[MessageList, str]): The path to a document or a list of messages.
700 memory_content (str, optional): The content of the memory to add.
701 doc_path (str, optional): The path to the document associated with the memory.
702 mem_cube_id (str, optional): The identifier of the MemCube to add the memories to.
703 If None, the default MemCube for the user is used.
704 user_id (str, optional): The identifier of the user to add the memories to.
705 If None, the default user is used.
706 session_id (str, optional): session_id
707 """
708 # user input messages
709 assert (messages is not None) or (memory_content is not None) or (doc_path is not None), (
710 "messages_or_doc_path or memory_content or doc_path must be provided."
711 )
712 # TODO: asure that session_id is a valid string
713 time_start = time.time()
714
715 target_session_id = session_id if session_id else self.session_id
716 target_user_id = user_id if user_id is not None else self.user_id
717 if mem_cube_id is None:
718 # Try to find a default cube for the user
719 accessible_cubes = self.user_manager.get_user_cubes(target_user_id)
720 if not accessible_cubes:
721 raise ValueError(
722 f"No accessible cubes found for user '{target_user_id}'. Please register a cube first."
723 )
724 mem_cube_id = accessible_cubes[0].cube_id # TODO not only first
725 else:
726 self._validate_cube_access(target_user_id, mem_cube_id)
727 logger.info(
728 f"time add: get mem_cube_id time user_id: {target_user_id} time is: {time.time() - time_start}"
729 )
730
731 if mem_cube_id not in self.mem_cubes:
732 raise ValueError(f"MemCube '{mem_cube_id}' is not loaded. Please register.")
733
734 sync_mode = self.mem_cubes[mem_cube_id].text_mem.mode
735 if sync_mode == "async":
736 assert self.mem_scheduler is not None, (
737 "Mem-Scheduler must be working when use asynchronous memory adding."
738 )
739 logger.debug(f"Mem-reader mode is: {sync_mode}")
740
741 def process_textual_memory():

Callers 15

test_add_messagesMethod · 0.95
getToolMetricsMethod · 0.45
handleMethod · 0.45
initOnlineTrackingMethod · 0.45
checkOfflineUsersMethod · 0.45
serveSearchMethod · 0.45
registerFunction · 0.45
getToolMetricsMethod · 0.45
handleMethod · 0.45
initOnlineTrackingMethod · 0.45

Calls 12

_validate_cube_accessMethod · 0.95
_get_all_documentsMethod · 0.95
TextualMemoryItemClass · 0.90
ScheduleMessageItemClass · 0.90
submitMethod · 0.80
infoMethod · 0.65
debugMethod · 0.65
get_user_cubesMethod · 0.45
get_memoryMethod · 0.45
submit_messagesMethod · 0.45

Tested by 3

test_add_messagesMethod · 0.76