Skip to main content
Memory management interface for MemMachine. This module provides the Memory class that handles episodic and profile memory operations for a specific context.

Class Memory

Memory interface for managing episodic and profile memory. This class provides methods for adding, searching, and managing memories within a specific context (group, agent, user, session).
def Memory(client: MemMachineClient, org_id: str, project_id: str, group_id: str | None, agent_id: str | list[str] | None, user_id: str | list[str] | None, session_id: str | None)
Parameters
NameTypeDescription
clientMemMachineClient-
org_idstr-
project_idstr-
group_id`strNone`-
agent_id`strlist[str]None`-
user_id`strlist[str]None`-
session_id`strNone`-

org_id

Get the org_id (read-only).
def org_id()
Parameters
NameTypeDescription
Returns Organization identifier

project_id

Get the project_id (read-only).
def project_id()
Parameters
NameTypeDescription
Returns Project identifier

user_id

Get the user_id list (read-only).
def user_id()
Parameters
NameTypeDescription
Returns List of user identifiers, or None if not set

agent_id

Get the agent_id list (read-only).
def agent_id()
Parameters
NameTypeDescription
Returns List of agent identifiers, or None if not set

group_id

Get the group_id (read-only).
def group_id()
Parameters
NameTypeDescription
Returns Group identifier, or None if not set

session_id

Get the session_id (read-only).
def session_id()
Parameters
NameTypeDescription
Returns Session identifier, or None if not set

add

Add a memory episode.
def add(content: str, role: str, producer: str | None, produced_for: str | None, episode_type: str, metadata: dict[str, Any] | None, timeout: int | None)
Parameters
NameTypeDescription
contentstrThe content to store in memory
rolestrMessage role - “user”, “assistant”, or “system” (default: “user”)
producer`strNone`Who produced this content (defaults to first user_id)
produced_for`strNone`Who this content is for (defaults to first agent_id)
episode_typestrType of episode (default: “text”) - stored in metadata
metadata`dict[str, Any]None`Additional metadata for the episode
timeout`intNone`Request timeout in seconds (uses client default if not provided)
Returns True if the memory was added successfully Raises requests.RequestException: If the request fails RuntimeError: If the client has been closed Search for memories.
def search(query: str, limit: int | None, filter_dict: dict[str, Any] | None, timeout: int | None)
Parameters
NameTypeDescription
querystrSearch query string
limit`intNone`Maximum number of results to return
filter_dict`dict[str, Any]None`Additional filters for the search
timeout`intNone`Request timeout in seconds (uses client default if not provided)
Returns Dictionary containing search results from both episodic and profile memory Raises requests.RequestException: If the request fails RuntimeError: If the client has been closed

get_context

Get the current memory context.
def get_context()
Parameters
NameTypeDescription
Returns Dictionary containing the context information

mark_client_closed

Mark this memory instance as closed by its owning client.
def mark_client_closed()
Parameters
NameTypeDescription