Include Luna AI Assistant design docs covering channels, configuration, core architecture, memory, scheduler, and skills. Add reference docs from OpenClaw and ZeroClaw projects, plus Mistral and OpenAI API specs.
3.0 KiB
Memory Module
Overview
The Memory module provides persistent conversation storage for the Luna AI Assistant. It uses a simple filesystem-based approach — conversation logs are written as plain text files and read back to seed new sessions with prior context.
The module consists of a single project: Luna.Memory.
Interface
public interface IMemoryStore
{
Task AddMemoryAsync(string memory);
Task<string> GetMemoriesAsync();
}
AddMemoryAsync— persists a conversation log or compaction summary to storage.GetMemoriesAsync— retrieves recent memories as a single concatenated string, used to seed new conversations.
Implementation
MemoryStore
MemoryStore is the concrete IMemoryStore implementation. It stores conversation logs as individual files on disk.
Storage path: ~/.luna/memory/conversations/
File naming: Luna_Conversation_Log_{yyyyMMddHHmmss}
public class MemoryStore : IMemoryStore
| Method | Behavior |
|---|---|
AddMemoryAsync |
Creates the storage directory if it does not exist, then writes the memory string to a new timestamped file. |
GetMemoriesAsync |
Reads the last 10 files (ordered by timestamp descending, parsed from the filename), concatenates their contents, and returns the result. Returns an empty string if no files exist. |
There is no database, no Redis, and no SQLite involved — persistence is purely filesystem-based.
Integration with the System
The SessionManager in Core injects IMemoryStore and uses it at three points:
-
Session creation — On the first message in a new conversation,
SessionManagercallsGetMemoriesAsync()and, if non-empty, prepends the result as aChatMessagewithChatRole.System. This gives the agent prior conversational context. -
Client disconnect — When a client disconnects,
SessionManager.ClientDisconnectedAsynctriggersSaveSessionLogAsync, which formats all user and assistant messages from the session and callsAddMemoryAsyncto persist the log. -
Compaction — When the session's token count exceeds the configured threshold (see Configuration
SessionOptions),SessionManageruses the Librarian agent to summarize older messages. The summary is retained in-session as an assistant message wrapped in:<---- MEMORY BEGIN ----> [Meta] Conversation Recorded at: {timestamp} {summary} <---- MEMORY END ---->
DI Registration
Memory services are registered via the AddMemory() extension method on IServiceCollection.
Dependencies
Project references: None (standalone module).
NuGet packages:
Microsoft.Extensions.Caching.MemoryMicrosoft.Extensions.DependencyInjection.AbstractionsMicrosoft.Extensions.Logging.AbstractionsMicrosoft.Extensions.OptionsStackExchange.Redis(present in csproj, currently unused)Microsoft.Data.Sqlite(present in csproj, currently unused)Microsoft.EntityFrameworkCore.Sqlite(present in csproj, currently unused)