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.1

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.1
File Size Uploaded
nowledge_mem_langgraph-0.1.1.tar.gz 170.1 kB Details

Built distribution (wheel)

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

Total release size: 184.7 kB

Release files / nowledge_mem_langgraph-0.1.1.tar.gz

Download URL nowledge_mem_langgraph-0.1.1.tar.gz
Size 170.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a4c8fa60f72ab42d9b4c75b233050311fd73b2b3da468cf76796a3f9694fc422
BLAKE2b-256 checksum
How to use checksums
63a3ec04a089a37ef57aa8d3cf2ee9b0d533c508ef3e44b96d13ecba9a8df97b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

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

Download URL nowledge_mem_langgraph-0.1.1-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ce02ce430ed514e46e16ddec2435b9e89d7041444ecff579d1bbd6ddf3d3413
BLAKE2b-256 checksum
How to use checksums
79757ae23ca9bb81de00093b6e4ebf42a87deac3b706fda84a219dafdee46440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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