Skip to content

Architecture

LivingMemory is built from event hooks, memory processing, retrieval fusion, storage, and a Pages API. Automatic memory and active agent tools share the same core data model so they do not become two separate memory systems.

LivingMemory runtime architecture

Runtime flow

  1. AstrBot receives a message and EventHandler captures session context.
  2. Before the LLM request, the recall pipeline searches long-term memory using the current message and optional recent context.
  3. Retrieved memories are injected into the request or returned as agent tool results.
  4. After the LLM responds, the reflection pipeline decides whether to summarize and store new memory.
  5. Background tasks handle decay, cleanup, backup, and index validation.

Main modules

ModuleResponsibility
main.pyRegisters the plugin, initializes runtime components, registers agent tools and Pages API
core/plugin_initializer.pyNon-blocking initialization, provider waiting, database migration, index loading
core/event_handler.pyGroup capture, memory recall, memory reflection
core/managers/memory_engine.pyUnified write, search, delete, and index maintenance
core/managers/graph_memory_manager.pyCoordinates graph nodes, edges, entries, and graph retrieval
core/managers/atom_lifecycle_manager.pyMaintains atom expiration, forgetting, reinforcement, and lifecycle state
core/retrieval/BM25, vector, graph, atom retrieval, and RRF fusion
storage/SQLite storage, graph storage, atom storage, database migration
pages/dashboard/AstrBot Pages management UI

Dual-route retrieval

Document memories and graph memories are searched through two routes:

RouteKeyword modeVector mode
Document routeBM25RetrieverVectorRetriever
Graph routeGraphKeywordRetrieverGraphVectorRetriever

RRFFusion merges the ranked lists, then the runtime applies importance, time decay, session filtering, and persona filtering.

Memory data model

TypeDescription
Session messagesRaw conversation context used for summarization triggers and expanded queries
Memory entriesLLM-generated long-term memories with summaries, importance, session, and persona metadata
Graph nodes and edgesEntities and relationships extracted from memories, with cross-memory merging
Memory atomsIndependent fact units with type, TTL, decay, and access reinforcement

Data safety

ScenarioProtection
Plugin version changeStartup creates a version-tagged backup
Database migrationBackup before migration
Index rebuildBatched rebuild with rollback on failure
Memory deletionTransactional deletion of related records
Dashboard operationsPages API reuses MemoryEngine and GraphStore instead of bypassing backend safety logic