EpisodicMemoryManager is the brain of the entire episodic memory system. It operates as a singleton—ensuring only one central manager exists—and acts as a factory, providing the methods you need to safely create and access memory for any specific conversation context.
Key Responsibilities:
- Registry: Tracks all active
EpisodicMemoryinstances to ensure each unique group, agent, user, and session combination gets its own dedicated memory. - Lifecycle Control: Manages memory instances from creation to safe closure, using reference counting to prevent premature cleanup.
- Session Management: Interacts with the underlying storage to persist metadata about groups and sessions (who is in the conversation, what the settings are).
- Configuration: Loads and merges base and session-specific configurations seamlessly.
Initialization and Access
You do not create the manager directly. You access its singleton instance through your main client object.EpisodicMemoryManager Class
EpisodicMemory instances, serving as a factory and central registry.
create_episodic_memory_manager
config_path: The path to the main configuration file (e.g.,memmachine.yaml).
EpisodicMemoryManager.
create_group
group_id: The unique ID for the group (e.g.,"team_alpha").agent_ids: A list of agent IDs belonging to this group.user_ids: A list of user IDs belonging to this group.
create_episodic_memory_instance
EpisodicMemory instance. This method will fail if the session_id already exists within the group_id.
Arguments:
group_id: The ID of the group the session belongs to (must exist).session_id: The unique identifier for this new session.configuration: Optional. A dictionary for session-specific settings that override the manager’s default configuration.
EpisodicMemory instance.
open_episodic_memory_instance
EpisodicMemory instance. If the memory instance is already active (e.g., another part of your application is using it), it safely increments the reference count and returns the shared instance.
Arguments:
group_id: The ID of the group.session_id: The ID of the existing session.
EpisodicMemory instance for the specified context.
async_open_episodic_memory_instance (Recommended)
async with statement. This is the recommended way to interact with existing memory instances.
It automatically calls open_episodic_memory_instance when entering the block and instance.close() when exiting the block, ensuring the reference count is properly managed.
async_create_episodic_memory_instance (Recommended)
async_open_episodic_memory_instance, this uses the async with pattern for creating a brand new memory instance. It handles the creation and guarantees safe closure upon exit.
get_episodic_memory_instance
create_episodic_memory_instance or open_episodic_memory_instance instead.
close_episodic_memory_instance
instance.close(), which decrements the reference count. If this was the last active reference, the memory instance is removed from the manager’s registry.
delete_context_memory
EpisodicMemory instance from the manager’s internal registry. It should only be called by an EpisodicMemory instance when its reference count drops to zero.
shut_down
EpisodicMemory instances and forces them to close, ensuring all resources are released.

