// learn · tutorial

Add memory to a LangChain agent in 5 minutes

Give a LangChain agent memory that survives across sessions using langgraph-agentram, the official AgentRAM integration. Install it, hand your agent four memory tools, and it saves and recalls facts on its own. No vector database, no embedding pipeline, and no coupling your memory to a framework that keeps changing.

The short version: pip install langgraph-agentram, call create_agentram_tools() with your API key, and pass the returned tools to your agent. It gets save_memory, recall_memory, search_memory, and list_memories, all backed by a hosted key-value API. The tools work in plain LangChain and in LangGraph. Full code below, about five minutes.

Why not just use LangChain's built-in memory?

You can, and for simple in-session history it works. But LangChain's memory abstractions have been redesigned repeatedly: ConversationBufferMemory gave way to RunnableWithMessageHistory, which gave way to LangGraph checkpointers. Each migration meant rewriting memory code, because the memory was coupled to the orchestration layer.

There is a durable alternative: keep the facts your agent needs to remember in a store that does not know or care which version of LangChain you are running. When the framework changes, your memory code does not. That is the approach here, and it happens to be the simplest one to get working too.

Before you start, you need:

Step 1: Get your AgentRAM key

// about 30 seconds

Sign up for AgentRAM and copy your API key. New accounts start with 1,000 free operations and no credit card, which is plenty to complete and test this tutorial. Keep the key handy for the next step.

Step 2: Create the memory tools

// about 1 minute

Install the package and create the tools with your key. That is the whole integration surface.

pip install langgraph-agentram
from langgraph_agentram import create_agentram_tools

tools = create_agentram_tools(api_key="agentram_your_key_here")
# -> [save_memory, recall_memory, search_memory, list_memories]

You get four tools an agent can call: save_memory stores a fact under a key, recall_memory reads one back, search_memory finds facts by text, and list_memories returns everything saved so far. They are ordinary LangChain tools, so they work with any LangChain agent.

Want to see them work before wiring up an agent? Call one directly, exactly as an agent would:

by_name = {t.name: t for t in tools}
by_name["save_memory"].invoke({"key": "name", "value": "Ada"})
by_name["recall_memory"].invoke({"key": "name"})   # -> "Ada"

That round trip is a live call to AgentRAM. The fact is now stored, and it will still be there in a completely new process.

Step 3: Give the tools to your agent

// about 1 minute

Pass the tools to your agent like any others. Here is a standard LangChain agent:

from langchain.chat_models import init_chat_model
from langchain.agents import create_agent
from langgraph_agentram import create_agentram_tools

tools = create_agentram_tools(api_key="agentram_your_key_here")
model = init_chat_model("openai:gpt-4o")

agent = create_agent(model, tools=tools)

The agent can now decide, on its own, to save something worth remembering or to look something up. There is no prompt-injection glue to write: the memory is just tools the model can call.

Step 4: Watch it remember across sessions

// about 1 minute

In one session, tell the agent something about yourself:

agent.invoke({"messages": [
    {"role": "user", "content": "Remember that my name is Ada and I like short answers."}
]})

The model calls save_memory to store those facts. Now stop the program and start a brand new session:

agent.invoke({"messages": [
    {"role": "user", "content": "What's my name?"}
]})
# the agent calls recall_memory, then answers: Ada

The second run is a fresh process with no conversation history, yet the agent knows the user, because the facts came from AgentRAM rather than the context window. That is persistent memory: it survived the process ending.

What just happened. LangChain handled the reasoning loop. AgentRAM handled the remembering, reachable as tools the model calls when it needs them. Neither depends on the other, so you can upgrade LangChain, switch models, or move to LangGraph without touching your memory code.

Using LangGraph? Use the native store

If you are on LangGraph, the same package ships a store that plugs straight into LangGraph's built-in long-term memory slot, no tools required. Long-term memory in LangGraph is JSON organized by a namespace and a key, which is exactly AgentRAM's shape:

from langchain.agents import create_agent
from langgraph_agentram import AgentRAMStore

store = AgentRAMStore(api_key="agentram_your_key_here")
agent = create_agent("openai:gpt-4o", tools=[], store=store)

The store and the tools share the same AgentRAM backend, so you can use either, or both. Reach for the tools when you want the model to manage memory explicitly, and the store when you want LangGraph to handle it natively.

Where to take it next

This pattern extends naturally:

The package is open source: langgraph-agentram on PyPI and on GitHub.

Get your free API key

Everything above runs on the free tier. 1,000 operations, no credit card, memory working in about five minutes.

Start building

Read the full API in the docs.

© 2026 AgentRAM. All rights reserved.