Skip to main content

Nowledge Mem for LangGraph

First-class, identity-aware memory for agents built with LangGraph. The connector keeps LangGraph responsible for execution and checkpointing while Nowledge Mem provides cross-agent context, governed memory, retrieval, and durable Threads.

Install

pip install nowledge-mem-langgraph

Run Nowledge Mem locally, or configure a remote Mem server:

export NMEM_API_URL=https://your-mem-server
export NMEM_API_KEY=nmem_...
export NMEM_LANGGRAPH_APP_ID=customer-support

NMEM_LANGGRAPH_APP_ID is a stable deployment slug. Keep it unchanged across releases so a LangGraph thread_id continues to map to the same Mem Thread.

create_agent: complete integration

from dataclasses import dataclass

from langchain.agents import create_agent
from nowledge_mem_langgraph import NowledgeClient, NowledgeMiddleware


@dataclass
class AgentContext:
    user_id: str
    nowledge: dict[str, str]


mem = NowledgeClient()
tools = await mem.tools()
agent = create_agent(
    model="openai:gpt-5.4",
    tools=tools,
    middleware=[NowledgeMiddleware(mem)],
    context_schema=AgentContext,
)

result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "What did we decide last week?"}]},
    config={"configurable": {"thread_id": "ticket-1842"}},
    context=AgentContext(
        user_id="auth-user-42",
        nowledge={
            "agent_id": "support-triage",
            "space_id": "customer-acme",
        },
    ),
)

The middleware:

  • reads the selected Agent's Context Bundle once per top-level turn
  • injects it into the model request without adding it to graph state or checkpoints
  • gives MCP calls trusted Agent and Space headers, overriding model-authored scope
  • imports the completed top-level conversation through POST /threads/import
  • skips nested subgraph checkpoints, so subagents do not duplicate the parent Thread
  • marks Mem retrieval tool results as external context so distillation cannot learn its own recalled output again

Both invoke() and ainvoke() work for middleware context and Thread sync. MCP tool loading and execution use the async interface provided by langchain-mcp-adapters, so agents using Mem tools should use ainvoke().

Agent identity

Identity and authorization are deliberately separate:

Value Meaning Example
API key Authorization and workspace access NMEM_API_KEY
agent_id Portable Nowledge Agent profile support-triage
host_agent_id LangGraph deployment provenance langgraph:support:prod-v3
space_id Memory and retrieval scope customer-acme
LangGraph thread_id Canonical conversation identity ticket-1842
LangGraph assistant_id Mutable deployment/config instance not a Thread ID

Put invocation-scoped selectors under context.nowledge. Do not derive them from prompt text or from LangGraph's authenticated user. A server graph_id and assistant_id are recorded automatically as host provenance when no explicit host_agent_id is supplied. They never grant access.

Static defaults use the portable environment variables:

export NMEM_AGENT_ID=support-triage
export NMEM_HOST_AGENT_ID=langgraph:support:prod
export NMEM_SPACE=customer-acme

Invocation context takes precedence over these defaults. If an invocation sets either Agent selector, the connector does not combine it with the other static selector; this prevents cross-tenant identity mixtures in shared deployments.

Raw StateGraph

Raw graphs have arbitrary topology, so no library can honestly infer the right model node or completion boundary. Use the explicit client helpers:

from nowledge_mem_langgraph import NowledgeClient, NowledgeIdentity

mem = NowledgeClient()
identity = NowledgeIdentity(agent_id="researcher", space_id="project-atlas")

bundle = await mem.acontext_bundle(identity)
tools = await mem.tools()

# At your graph's real completion boundary:
await mem.async_thread(
    thread_id=runtime.execution_info.thread_id,
    messages=state["messages"],
    identity=identity,
    runtime=runtime,
)

Keep Context Bundle text transient in the model request. Do not add it to a checkpointed messages channel.

Subagents and subgraphs

LangGraph subgraphs share the parent thread_id and receive a nested checkpoint namespace. The middleware syncs only the top-level namespace. This produces one canonical Mem Thread for the user conversation while preserving subagent activity in LangGraph's own checkpoints and traces.

If a subagent is an independently addressable product agent with its own durable conversation, give it a different LangGraph thread_id and its own Nowledge Agent identity. Do not use assistant_id to split a shared conversation.

Reliability boundary

Context reads and Thread sync are fail-open by default: a transient Mem outage does not take down the customer agent. Set fail_open=False for workflows where memory availability is mandatory. Scope and authorization are never relaxed on failure.

Thread sync is awaited rather than dispatched as an untracked background task, so serverless workers cannot terminate before the import finishes. Exact replays are no-ops and longer conversations append only their missing messages.

What this connector is not

  • It is not a LangGraph checkpointer. Keep the checkpointer that owns execution state.
  • It is not a BaseStore replacement. Memories have provenance, governance, and semantic relationships that a generic key-value store does not represent.
  • It does not use LangSmith traces as transcripts. Traces contain nested execution events, not the canonical user conversation.
  • It cannot recover messages summarized away before the connector was installed.

See the full guide for deployment and migration guidance.

Metadata

Release files for nowledge-mem-langgraph 0.1.2

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

Source distribution (sdist)

Source distribution for nowledge-mem-langgraph 0.1.2
File Size Uploaded Provenance Actions
nowledge_mem_langgraph-0.1.2.tar.gz 171.2 kB With provenance Details for nowledge_mem_langgraph-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nowledge-mem-langgraph 0.1.2
File Interpreter ABI Platform Actions
nowledge_mem_langgraph-0.1.2-py3-none-any.whl Python 3 none any Details for nowledge_mem_langgraph-0.1.2-py3-none-any.whl

Total release size: 186.0 kB

Release files / nowledge_mem_langgraph-0.1.2.tar.gz

Download URL nowledge_mem_langgraph-0.1.2.tar.gz
Size 171.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a3427ba0f81080f42ff6cb8866026d8369bc9e16d64d29cf061a2bd7cf9fc101
BLAKE2b-256 checksum
How to use checksums
8c486578a05e58158f73ba497ab83cc3f86116df26d59ec420f780126f29e446
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / nowledge_mem_langgraph-0.1.2-py3-none-any.whl

Download URL nowledge_mem_langgraph-0.1.2-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
025169e65edff837e7d35c9310e7c0e10305e50f730f8d2d6da12cf879005c7e
BLAKE2b-256 checksum
How to use checksums
2ca767edf532378ccad0176796da1c03b58efd71b50e4c2cf1d1d78a1381074c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for nowledge-mem-langgraph 0.1.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nowledge_mem_langgraph-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

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.

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