add_memory
Store information like facts, preferences, or events in MemoVault's long-term memory system for persistence across sessions.
Instructions
Store new information in memory.
Use this to remember facts, preferences, events, or any important information the user wants to persist across sessions.
Args: content: The information to remember memory_type: Optional type (fact, preference, event, opinion, procedure, personal)
Returns: Confirmation message with the memory ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| memory_type | No |
Implementation Reference
- src/memovault/api/mcp.py:40-62 (handler)The MCP tool handler function that implements add_memory. Decorated with @self.mcp.tool(), it accepts content and optional memory_type, creates a memory item with metadata, and returns a confirmation message with the memory ID.
async def add_memory(content: str, memory_type: str | None = None) -> str: """Store new information in memory. Use this to remember facts, preferences, events, or any important information the user wants to persist across sessions. Args: content: The information to remember memory_type: Optional type (fact, preference, event, opinion, procedure, personal) Returns: Confirmation message with the memory ID """ try: metadata = {} if memory_type: metadata["type"] = memory_type ids = self.vault.add(content, **metadata) return f"Memory stored successfully (ID: {ids[0]})" except Exception as e: logger.error(f"Error adding memory: {e}") return f"Error storing memory: {str(e)}" - src/memovault/api/models.py:6-11 (schema)Pydantic BaseModel defining the AddMemoryRequest schema with content (required string), type (optional string), and tags (optional string list) fields for input validation.
class AddMemoryRequest(BaseModel): """Request to add a memory.""" content: str = Field(..., description="Memory content to add") type: str | None = Field(default=None, description="Memory type") tags: list[str] | None = Field(default=None, description="Memory tags") - src/memovault/api/mcp.py:36-62 (registration)The _setup_tools() method where add_memory is registered as an MCP tool. The @self.mcp.tool() decorator at line 39 registers the function with the FastMCP framework.
def _setup_tools(self): """Set up MCP tools.""" @self.mcp.tool() async def add_memory(content: str, memory_type: str | None = None) -> str: """Store new information in memory. Use this to remember facts, preferences, events, or any important information the user wants to persist across sessions. Args: content: The information to remember memory_type: Optional type (fact, preference, event, opinion, procedure, personal) Returns: Confirmation message with the memory ID """ try: metadata = {} if memory_type: metadata["type"] = memory_type ids = self.vault.add(content, **metadata) return f"Memory stored successfully (ID: {ids[0]})" except Exception as e: logger.error(f"Error adding memory: {e}") return f"Error storing memory: {str(e)}" - The core MemoVault.add() method that performs the actual memory addition. It normalizes input to MemoryItem objects and delegates to the MemCube for storage, returning a list of memory IDs.
def add( self, content: str | list[str] | MemoryItem | list[MemoryItem], **metadata: Any, ) -> list[str]: """Add memories. Args: content: Memory content (string, list of strings, or MemoryItem). **metadata: Additional metadata to attach to memories. Returns: List of memory IDs that were added. Example: >>> mem.add("I prefer dark mode") >>> mem.add(["Fact 1", "Fact 2"], type="fact") """ # Normalize input to list if isinstance(content, str): items = [MemoryItem(memory=content, metadata=metadata)] elif isinstance(content, MemoryItem): items = [content] elif isinstance(content, list): items = [] for item in content: if isinstance(item, str): items.append(MemoryItem(memory=item, metadata=metadata)) elif isinstance(item, MemoryItem): items.append(item) else: items.append(MemoryItem(**item)) else: items = [MemoryItem(**content)] return self._cube.add(items)