AgentrySimpleMem is the class that powers long-term memory in Logicore. It manages a per-user (or per-session) LanceDB table, queues dialogue turns for processing, and serves semantic retrieval results to the agent’s LLM context.
Import path:
Default Integration
When you create an agent withmemory=True, Logicore automatically instantiates AgentrySimpleMem and wires it into the chat loop:
on_user_message(), on_assistant_message(), and process_pending() automatically.
Constructor Parameters
Identifier for the user or agent role. Used as part of the LanceDB table name. All non-alphanumeric characters are replaced with underscores.
Session identifier. Combined with
user_id to form the table name when isolate_by_session=True. Can be any string — it is sanitised before use.Maximum number of memory strings returned by a single retrieval call. Maps directly to the
top_k parameter of the vector search.Reserved for future background thread processing. Currently, all processing is driven by explicit
process_pending() calls.When
True, each session_id maps to a separate LanceDB table (memories_<user>_<session>). When False, all sessions for a user_id share a single table (memories_<user>), enabling cross-session recall.Enables verbose logging to stdout. Logs include table initialization, queued dialogue snippets, retrieval counts, and processing results.
Methods
on_user_message(content) -> List[str]
Called when the user sends a message. Queues the message for later persistence and immediately performs a semantic search to return relevant memory strings for LLM context augmentation.
on_assistant_message(content)
Called after the assistant responds. Queues the response for later processing by process_pending().
process_pending()
Processes the dialogue queue and persists qualifying facts to LanceDB. This is called automatically by Agent after each chat turn.
- Drains
_dialogue_queueunder a lock. - For each queued
Dialogue, calls_should_store_dialogue()to gate on signal score. - Calls
_extract_atomic_facts()to split the turn into scored fact strings. - Constructs
MemoryEntryobjects and callsVectorStore.add_entries().
get_stats() -> Dict[str, Any]
Returns a snapshot of the current memory state:
clear_memories()
Drops the entire LanceDB table for this user/session. The table will be recreated on the next write.
Integration Examples
- Agent (auto-managed)
- BasicAgent
- MCPAgent
- Manual instance
The recommended approach — pass
memory=True and let the agent manage everything:Cross-Session Shared Memory
By default, each session writes to and reads from its own LanceDB table. To share one memory pool across all sessions for the same user, replace the defaultsimplemem instance after agent creation:
When
isolate_by_session=False, changing the session_id on the agent has no effect on which LanceDB table is used. All sessions resolve to memories_<user_id>.Table Naming
Table names are derived byget_memory_table_name() from logicore.simplemem.config:
user_id and session_id are replaced with underscores.
Embedding Backend
AgentrySimpleMem uses EmbeddingModel for both storing and retrieving memories. The default backend is Ollama with the qwen3-embedding:0.6b model (1024-dimensional embeddings).
EMBEDDING_MODEL environment variable:
Changing the embedding model after data has been written to a table is not supported. The vector dimensions must match. Create a new table (use a different
session_id or call clear_memories()) when switching models.Observability
Best Practices
Stable session IDs
Use stable, unique session IDs for workflows that need continuity (e.g.,
user-<id>-<project>). Avoid random UUIDs if you want memory to persist across restarts.Shared tables for user profiles
Use
isolate_by_session=False only when you want a persistent user profile that spans all sessions. This is ideal for personal assistants, not multi-tenant services.Avoid storing sensitive data
Do not store PII, credentials, or regulated data unless you have appropriate access controls and data governance policies in place.
Monitor total_memories
Use
get_stats() periodically to track table growth. Call clear_memories() and rebuild if the table becomes stale or oversized.