Skip to content

Long-Term Memory

Short-term memory lives for one run. Long-term memory (LTM) persists across runs and sessions. Wire a backend into the context via long_term_memory=:

from mmar_carl import ReasoningContext, InMemoryLTM, JsonFileLTM
context = ReasoningContext(
outer_context=data,
api=client,
long_term_memory=JsonFileLTM("ltm.json"), # or InMemoryLTM()
session_id="user-42", # scopes LTM entries
)
BackendPersistence
InMemoryLTMIn-process only (lost on exit). Good for tests.
JsonFileLTM("path.json")Persisted to a JSON file across runs.

Both implement LTMBase — subclass it to back LTM with your own database.

From a step, read an LTM value with the $ltm.key reference. Programmatically:

context.ltm_retrieve("preferred_tone") # exact-key lookup (None if absent)
context.recall("past decisions about pricing", top_k=5) # similarity search

LTMBase defines store, retrieve, delete, search, and clear — all session-scoped via the session_id keyword (defaults to the context’s session_id).