LangChain integration for Engram — cognitive memory infrastructure for AI agents
Project description
langchain-engram
LangChain integration for Engram — cognitive memory infrastructure for AI agents.
Engram stores memories with confidence scores, detects contradictions, and manages memory lifecycle (decay, consolidation, tier promotion). Unlike a conversation buffer, it surfaces what the agent is most confident about — not just what was said most recently.
Installation
pip install langchain-engram
This also installs engram.to, the Engram Python SDK.
Setup
You need a running Engram server and an API key. Keys are prefixed mk_ (master, all scopes) or rk_ (restricted, user-chosen scopes).
export ENGRAM_BASE_URL=http://localhost:8080 # your Engram server
export ENGRAM_API_KEY=mk_your_key_here
Or pass them explicitly to each class.
EngramChatMemory
Drop-in replacement for ConversationBufferMemory. Stores each conversation turn as Engram memories and retrieves semantically relevant context on the next turn — not a flat buffer.
from langchain_engram import EngramChatMemory
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI
memory = EngramChatMemory(
agent_id="your-agent-uuid",
# api_key and base_url read from env if not passed
)
chain = ConversationChain(llm=ChatOpenAI(), memory=memory)
chain.predict(input="I always prefer dark mode in all my tools")
chain.predict(input="I'm a backend engineer, mostly Go and Rust")
# Next session — memories are recalled from Engram, not kept in RAM
response = chain.predict(input="What do you know about my preferences?")
Return as messages
memory = EngramChatMemory(
agent_id="your-agent-uuid",
return_messages=True, # returns List[BaseMessage] instead of a string
min_confidence=0.7, # only confident memories
top_k=5,
)
Configuration
| Parameter | Default | Description |
|---|---|---|
agent_id |
required | Engram agent UUID |
api_key |
ENGRAM_API_KEY env |
mk_ or rk_ prefixed API key |
base_url |
ENGRAM_BASE_URL env |
Engram server URL |
memory_key |
"history" |
Key injected into chain inputs |
input_key |
auto-detected | Key in inputs holding the human message |
output_key |
auto-detected | Key in outputs holding the AI response |
return_messages |
False |
Return List[BaseMessage] instead of a string |
top_k |
10 |
Max memories to retrieve per turn |
min_confidence |
None |
Confidence floor — filters out uncertain memories |
EngramRetriever
Use Engram as a retriever in any LangChain chain or agent. Retrieves memories using Engram's hybrid vector + knowledge-graph recall.
from langchain_engram import EngramRetriever
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI
retriever = EngramRetriever(
agent_id="your-agent-uuid",
top_k=5,
min_confidence=0.6,
)
qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever)
answer = qa.invoke({"query": "What are the user's display preferences?"})
Each retrieved Document carries full metadata:
docs = retriever.invoke("display preferences")
for doc in docs:
print(doc.page_content)
print(f" confidence: {doc.metadata['confidence']:.0%}")
print(f" tier: {doc.metadata['tier']}") # hot / warm / cold
print(f" type: {doc.metadata['memory_type']}") # fact / preference / decision
print(f" score: {doc.metadata['score']:.3f}") # combined recall score
Configuration
| Parameter | Default | Description |
|---|---|---|
agent_id |
required | Engram agent UUID |
api_key |
ENGRAM_API_KEY env |
API key |
base_url |
ENGRAM_BASE_URL env |
Engram server URL |
top_k |
10 |
Max memories to return |
min_confidence |
None |
Confidence floor |
memory_type |
None |
Filter: "fact", "preference", "decision", "constraint" |
graph_weight |
None |
Graph/vector blend (0–1). Server default: 0.4 graph / 0.6 vector |
API key scopes
| Key prefix | Scopes | Use case |
|---|---|---|
mk_... |
admin + read + write | Server setup, key management |
rk_... |
user-chosen | Production agents (read + write is sufficient) |
For LangChain usage, a rk_ key with read and write scopes is all you need.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_engram-0.1.0.tar.gz.
File metadata
- Download URL: langchain_engram-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1df147a1f383d6fd16fac9b7ec981364f6f0e86e45c0b5bd60a3e8e64af295a3
|
|
| MD5 |
c661d707a75e1543680f3fa066067792
|
|
| BLAKE2b-256 |
3caf7b0ee79f91bd853e9c1bd2fba3fe76cce9462871aa654edd49b4917196f4
|
File details
Details for the file langchain_engram-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_engram-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6838a6783d98cdf0636c0667df43c8d2ff77d0b8929d6166c6b45c3182a34e79
|
|
| MD5 |
6f67f74cfc1528bc7cdc205c4f67f7dd
|
|
| BLAKE2b-256 |
56cc7e042d63d2cfd055496ee98a80063a351e969f992cfe9df4a24de0b239e5
|