MemScheduler: The Scheduler for Memory Organization

MemScheduler is a concurrent memory management system parallel running with the MemOS system, which coordinates memory operations between working memory, long-term memory, and activation memory in AI systems. It handles memory retrieval, updates, and compaction through event-driven scheduling.
This system is particularly suited for conversational agents and reasoning systems requiring dynamic memory management.

Memory Scheduler Overview

MemScheduler is a concurrent memory management system that works in parallel with MemOS, coordinating memory operations across working memory, long-term memory, and activation memory in AI systems. Designed for conversational agents and reasoning systems, it provides dynamic memory management through event-driven scheduling.

Key Features

  • 🚀 Concurrent operation with MemOS system
  • 🧠 Multi-memory coordination (Working/Long-Term/User memory)
  • Event-driven scheduling for memory operations
  • 🔍 Efficient retrieval of relevant memory items
  • 📊 Comprehensive monitoring of memory usage
  • 📝 Detailed logging for debugging and analysis

Memory Scheduler Architecture

The MemScheduler system is structured around several key components:

  1. Message Handling: Processes incoming messages through a dispatcher with labeled handlers
  2. Memory Management: Manages different memory types (Working, Long-Term, User)
  3. Retrieval System: Efficiently retrieves relevant memory items based on context
  4. Monitoring: Tracks memory usage, frequencies, and triggers updates
  5. Dispatcher (Router): Trigger different memory reorganization strategies by checking messages from MemOS systems.
  6. Logging: Maintains logs of memory operations for debugging and analysis

Message Processing

The scheduler processes messages through a dispatcher with dedicated handlers:

Message Types

Message TypeHandler MethodDescription
QUERY_LABEL_query_message_consumeHandles user queries and triggers retrieval
ANSWER_LABEL_answer_message_consumeProcesses answers and updates memory usage

Schedule Message Structure

The scheduler processes messages from its queue using the following format:

ScheduleMessageItem:

FieldTypeDescription
item_idstrUUID (auto-generated) for unique identification
user_idstrIdentifier for the associated user
mem_cube_idstrIdentifier for the memory cube
labelstrMessage label (e.g., QUERY_LABEL, ANSWER_LABEL)
mem_cube`GeneralMemCubestr`
contentstrMessage content
timestampdatetimeTime when the message was submitted

Meanwhile the scheduler will send the scheduling messages by following structures.

ScheduleLogForWebItem:

FieldTypeDescriptionDefault Value
item_idstrUnique log entry identifier (UUIDv4)Auto-generated (uuid4())
user_idstrAssociated user identifier(Required)
mem_cube_idstrLinked memory cube ID(Required)
labelstrLog category identifier(Required)
from_memory_typestrSource memory partition
Possible values:
- "LongTermMemory"
- "UserMemory"
- "WorkingMemory"
(Required)
to_memory_typestrDestination memory partition(Required)
log_contentstrDetailed log message(Required)
current_memory_sizesMemorySizesCurrent memory utilization
DEFAULT_MEMORY_SIZES = {
"long_term_memory_size": -1,
"user_memory_size": -1,
"working_memory_size": -1,
"transformed_act_memory_size": -1
}
memory_capacitiesMemoryCapacitiesMemory partition limits
DEFAULT_MEMORY_CAPACITIES = {
"long_term_memory_capacity": 10000,
"user_memory_capacity": 10000,
"working_memory_capacity": 20,
"transformed_act_memory_capacity": -1
}
timestampdatetimeLog creation timeAuto-set (datetime.now)

Execution Example

examples/mem_scheduler/schedule_w_memos.py is a demonstration script showcasing how to utilize the MemScheduler module. It illustrates memory management and retrieval within conversational contexts.

Code Functionality Overview

This script demonstrates two methods for initializing and using the memory scheduler:

  1. Automatic Initialization: Configures the scheduler via configuration files
  2. Manual Initialization: Explicitly creates and configures scheduler components

The script simulates a pet-related conversation between a user and an assistant, demonstrating how memory scheduler manages conversation history and retrieves relevant information.

Core Code Structure

def init_task():
    # Initialize sample conversations and questions
    conversations = [
        {"role": "user", "content": "I just adopted a golden retriever puppy yesterday."},
        {"role": "assistant", "content": "Congratulations! What did you name your new puppy?"},
        # More conversations...
    ]

    questions = [
        {"question": "What's my dog's name again?", "category": "Pet"},
        # More questions...
    ]
    return conversations, questions

def run_with_automatic_scheduler_init():
    # Automatic initialization: Load configuration from YAML files
    # Create user and memory cube
    # Add conversations to memory
    # Process user queries and display answers
    # Show web logs

def run_with_manual_scheduler_init():
    # Manual initialization: Explicitly create and configure scheduler components
    # Initialize MemOS, user, and memory cube
    # Manually submit messages to the scheduler
    # Process user queries and display answers
    # Show web logs

if __name__ == '__main__':
    # Run both initialization methods sequentially
    run_with_automatic_scheduler_init()
    run_with_manual_scheduler_init()
Memtensor
© 2025 Memtensor, Inc. All rights reserved.