LangChain + MEMANTO
How It Works
MemAntoMemory in wherever LangChain expects a BaseMemory. It handles session activation, storing new messages, and injecting recalled context into your prompts.
Prerequisites
- Python 3.8+
- Moorcheh API key
- MEMANTO server running locally
Install
Step 1: Start MEMANTO Server
Step 2: Create the Memory Class
Creatememanto_memory.py:
Step 3: Use in a Chain
Createagent.py:
Step 4: Run
Using with LCEL (LangChain Expression Language)
Inject recalled memory directly into an LCEL pipeline:Using MEMANTO’s Built-in Answer (Optional)
For cases where you want a direct, grounded response from memory without routing through your chain, MEMANTO exposes ananswer endpoint that uses its native RAG model. No external LLM call is made on your side.
This is useful as a quick lookup tool — for example, answering a simple factual question about a user before deciding whether to invoke the full chain.
memanto_answer first, and only invoke the full LLM if the memory answer is empty:
When to useanswervsrecall
- Use
recall(viaload_memory_variables) when your LLM should reason over the raw memories itself.- Use
answerwhen you want a ready-made response from memory, or to short-circuit the chain for simple factual lookups.
Persistent Memory Across Sessions
Memories stored viasave_context survive process restarts and are available in future sessions for the same agent_id: