I'll explore your project to understand the MemoryManager and its usage. Let me start by looking at the codebase structure.
[tool: list_dir — Tool use: list_dir • Listed current directory, 35 results]
Let me look at the main source directory to understand the project structure.
[tool: list_dir — Tool use: list_dir • Listed directory src, 5 results]
Let's examine the memory directory to understand the memory management components.
[tool: list_dir — Tool use: list_dir • Listed directory src/memory, 7 results]
Let's look at the base memory manager to understand the fundamental structure:
[tool: read_file — Tool use: read_file • Read file: src/memory/base_memory_manager.py]
Now let's look at the main memory manager implementation:
[tool: read_file — Tool use: read_file • Read file: src/memory/memory_manager.py]
Let's check a few more things to get a better picture of the project:
[tool: read_file — Tool use: read_file • Read file: README.md]
Now let's see the memory manager documentation:
[tool: read_file — Tool use: read_file • Read file: src/memory/README-memory-manager.md]
Let's look at one of the examples to see how the system is actually used:
[tool: list_dir — Tool use: list_dir • Listed directory examples, 8 results]
[tool: read_file — Tool use: read_file • Read file: examples/memory_manager_usage_example.py]
Let's look at one more example to understand how the agent utilizes the memory manager:
[tool: read_file — Tool use: read_file • Read file: examples/agent_usage_example.py]
Let's also check if we can find any template files used for prompting:
[tool: list_dir — Tool use: list_dir • Listed directory src/memory/templates, 4 results]
[tool: read_file — Tool use: read_file • Read file: src/memory/templates/create_memory.prompt]
Based on the code I've examined, here's a detailed description of your project:
LLM-Driven Agent with Session Memory
This is a sophisticated framework for building domain-agnostic LLM-powered agents with persistent memory capabilities. The system is designed to maintain context across multiple sessions, organize complex information dynamically, and adapt to different domains through configuration rather than code changes.
Core Architecture
The project is structured around three main components:
1. Memory Management System
At the heart of the system is a flexible, LLM-driven memory manager that uses a structured approach to organize and persist information:
-
BaseMemoryManager: An abstract base class that defines core persistence functionality and the interface for all memory operations.
-
MemoryManager: The primary implementation that uses LLM to dynamically organize information with a sophisticated memory structure:
- Static Memory: Read-only foundational knowledge about the domain
- Working Memory: Dynamic information learned during interactions
- Knowledge Graph: Explicit relationships between entities
- Conversation History: Complete record of all interactions
- Metadata: System information like timestamps and version
-
SimpleMemoryManager: A straightforward implementation for testing and simpler use cases that maintains a flat memory structure.
The memory manager uses prompt templates to instruct the LLM on how to structure, query, and update memory. Rather than hard-coding schemas, it allows the LLM to determine the most appropriate way to organize information based on the context.
2. LLM Service Layer
The system abstracts interactions with language models through a service layer:
- OllamaService: Connects to local LLM deployments via Ollama
- Supports both streaming and non-streaming responses
- Includes configurable debug logging for troubleshooting
3. Agent Layer
The agent orchestrates the interaction flow, manages conversation phases, and coordinates between the user and memory:
- Agent: Manages the conversation flow through distinct phases:
- INITIALIZATION: Setting up initial domain knowledge
- LEARNING: Acquiring new domain information
- INTERACTION: Regular conversation
- Automatically triggers memory reflection after a configurable number of messages
- Maintains phase-specific handling of user inputs
Key Features
-
Domain Agnosticism: The system can be adapted to different domains through configuration files rather than code changes.
-
Persistent Memory: All interactions are saved to disk, allowing conversations to continue across multiple sessions.
-
Memory Reflection: The system periodically reviews conversation history to identify and extract important information into the structured working memory.
-
Flexible Knowledge Representation: The memory structure is adaptable, allowing the LLM to determine the optimal organization for different domains.
-
Robust Error Handling: The system includes mechanisms for graceful error handling, including memory backups and recovery.
-
Debug Logging: Comprehensive logging of all LLM interactions with scoped outputs for easier debugging.
Implementation Details
-
Prompt Engineering: The system uses carefully crafted prompt templates to instruct the LLM on how to structure, query, and update memory.
-
JSON Persistence: Memory is stored in JSON format with automatic backups created on each save operation.
-
Domain Configurations: Different domains (like D&D campaigns or user story generation) are defined through configuration objects that include schema suggestions and domain-specific prompts.
-
Conversation History Management: All interactions are tracked and used for both direct responses and periodic memory reflection.
Example Use Cases
The repository includes examples demonstrating the system's versatility:
-
D&D Campaign Management: Creating and managing a virtual D&D campaign world, including locations, characters, and plot elements.
-
User Story Generation: Assisting in requirements gathering and feature planning for software projects.
-
Basic Memory Operations: Demonstrating direct memory creation, querying, and reflection processes.
The framework is set up to be easily extended to new domains by providing appropriate domain configurations, without needing to modify the core code.
Technical Implementation
The project uses modern Python patterns including abstract base classes, typed interfaces, and modular design. It has a proper package structure with pyproject.toml for installation and dependencies. The code leverages asyncio for efficient handling of LLM operations and includes comprehensive error handling throughout.
The memory system demonstrates a sophisticated approach to knowledge management, using the LLM itself to determine the best way to structure and organize information rather than hard-coding schemas, which makes it highly adaptable to different domains and use cases.