Skip to main content

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

Metadata

Release files for langchain-engram 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-engram 0.1.0
File Size Uploaded Provenance
langchain_engram-0.1.0.tar.gz 13.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-engram 0.1.0
File Interpreter ABI Platform
langchain_engram-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / langchain_engram-0.1.0.tar.gz

Download URL langchain_engram-0.1.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1df147a1f383d6fd16fac9b7ec981364f6f0e86e45c0b5bd60a3e8e64af295a3
BLAKE2b-256 checksum
How to use checksums
3caf7b0ee79f91bd853e9c1bd2fba3fe76cce9462871aa654edd49b4917196f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / langchain_engram-0.1.0-py3-none-any.whl

Download URL langchain_engram-0.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6838a6783d98cdf0636c0667df43c8d2ff77d0b8929d6166c6b45c3182a34e79
BLAKE2b-256 checksum
How to use checksums
56cc7e042d63d2cfd055496ee98a80063a351e969f992cfe9df4a24de0b239e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for langchain-engram 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page