Add recall and save nodes to LangGraph.

A graph can recall context before response generation and save a turn afterward. Those are explicit operations in your graph, so you control scope and timing.

Minimal example

Use these values on a trusted local machine or server. Keep project credentials out of browser code.

python
import os
from typing import TypedDict
from langchain_openai import ChatOpenAI
from langgraph.graph import START, END, StateGraph
from langchain_memorae import MeMoraeMemory

# Set MEMORAE_API_KEY, MEMORAE_SUBJECT_ID, OPENAI_API_KEY and
# MEMORAE_BASE_URL=https://memora-singapore.onrender.com on your server.
memory = MeMoraeMemory(
    api_key=os.environ["MEMORAE_API_KEY"],
    base_url=os.environ["MEMORAE_BASE_URL"],
    subject_id=os.environ["MEMORAE_SUBJECT_ID"],
    namespace=os.getenv("MEMORAE_NAMESPACE", "default"),
)
llm = ChatOpenAI()

class State(TypedDict):
    input: str
    history: str
    output: str

def recall(state: State) -> dict:
    return memory.load_memory_variables({"input": state["input"]})

def respond(state: State) -> dict:
    reply = llm.invoke([
        ("system", "Relevant user memories:\n" + state["history"]),
        ("human", state["input"]),
    ]).content
    return {"output": reply}

def save(state: State) -> dict:
    memory.save_context({"input": state["input"]}, {"output": state["output"]})
    return {}

builder = StateGraph(State)
for name, node in (("recall", recall), ("respond", respond), ("save", save)):
    builder.add_node(name, node)
builder.add_edge(START, "recall")
builder.add_edge("recall", "respond")
builder.add_edge("respond", "save")
builder.add_edge("save", END)
graph = builder.compile()
print(graph.invoke({"input": "What do you remember about me?"})["output"])

Check that it works

  1. Invoke the graph with an authenticated user’s stable subject ID configured on the memory instance.
  2. Confirm the recall node can return an empty history when there is no relevant memory.
  3. After the save node runs, allow asynchronous processing before checking retrieval.
  4. Inspect source citations in the dashboard or returned retrieval documents.

MAKE CONTEXT CARRY FORWARD

Continue with the product docs.

Learn the memory model, API configuration, lifecycle, and troubleshooting.

Get started