MemClaw / docs
Integrations

LangChain

Give a LangChain or LangGraph agent persistent, governed memory with MemClaw — over MCP or the REST API.

MemClaw is framework-agnostic: it speaks MCP and plain REST. There are two clean ways to give a LangChain (or LangGraph) agent long-term memory with it.

MemClaw is MCP-native, so the simplest path is to load its memclaw_* tools straight into your agent with langchain-mcp-adapters. Your agent gets the full surface — memclaw_write, memclaw_recall, memclaw_manage, and the rest — with no glue code per tool.

pip install langchain-mcp-adapters langgraph "langchain[openai]"
import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

client = MultiServerMCPClient({
  "memclaw": {
      "url": "https://memclaw.net/mcp",
      "transport": "streamable_http",
      # Use an agent-scoped key in production (see Per-agent keys below).
      "headers": {"X-API-Key": "mc_xxx"},
  }
})

async def main():
  tools = await client.get_tools()              # all memclaw_* tools
  agent = create_react_agent("openai:gpt-4o", tools)
  result = await agent.ainvoke({
      "messages": [{"role": "user", "content": "Remember that our Q3 revenue target is $4M, then tell me what it is."}]
  })
  print(result["messages"][-1].content)

asyncio.run(main())

Option B — over REST (no MCP)

If you'd rather not run an MCP client, wrap MemClaw's two core endpoints — POST /api/v1/memories and POST /api/v1/recall — as ordinary LangChain tools.

pip install langchain langchain-openai requests
import requests
from langchain_core.tools import tool

MEMCLAW_URL = "https://memclaw.net"
HEADERS = {"X-API-Key": "mc_xxx"}
TENANT = "my-team"

@tool
def remember(content: str) -> str:
  """Persist a fact to long-term memory for later recall."""
  r = requests.post(
      f"{MEMCLAW_URL}/api/v1/memories",
      headers=HEADERS,
      json={"tenant_id": TENANT, "agent_id": "langchain-agent", "content": content},
  )
  r.raise_for_status()
  return "saved"

@tool
def recall(query: str) -> str:
  """Search long-term memory for facts relevant to the query."""
  r = requests.post(
      f"{MEMCLAW_URL}/api/v1/recall",
      headers=HEADERS,
      json={"tenant_id": TENANT, "query": query},
  )
  r.raise_for_status()
  return r.text

Bind the tools to any LangChain agent or LangGraph create_react_agent the same way you would any other tool:

from langgraph.prebuilt import create_react_agent

agent = create_react_agent("openai:gpt-4o", [remember, recall])

Always pass a real agent_id (the REST example uses "langchain-agent"). The reserved default identity is rejected server-side, so writes silently no-op without one. For anything beyond a prototype, give each agent its own agent-scoped credential — see Per-agent keys — so trust gating, fleet membership, and per-agent keystones apply.

Where memory lives

Both paths write to the same governed store: every memory is enriched, scoped, and audit-logged. Recall returns the relevant slice rather than the full history, which is what keeps token cost flat as the conversation grows. See Memory Pipeline for what happens between write and a memory becoming recallable.