Skip to main content
Building an AI agent that actually remembers users is one of those features that sounds hard but turns out to be surprisingly straightforward with Remem. This guide walks you through a complete, working customer support agent that loads what it knows about a user before responding, then saves what it just learned — so the next session picks up right where the last one left off.

What We’re Building

The agent follows a simple loop on every message:
  1. User sends a message — a support question, a preference, a fact about themselves.
  2. Agent loads memory contextclient.context() fetches the most relevant memories for this user before the agent says a word.
  3. Agent responds — the LLM generates a reply with full context of who this person is.
  4. Agent saves what it learnedclient.remember() stores the user’s message as an episodic memory.
  5. Next session — the agent already knows the user. No re-introduction needed.

Prerequisites

Install the required packages:
Create a .env file with your API keys:
Get your Remem API key from the dashboard. See the authentication guide for details on key types and scopes.

Steps

1

Set up environment variables

Load your API keys from the .env file using python-dotenv. Never hard-code keys in source files.
2

Initialize both clients

Create a RememClient for memory and an OpenAI client for the LLM. You also need an AGENT_ID — a stable string that scopes memories to this specific agent so different bots don’t share memories.
3

Load context at session start

Before generating a response, call client.context() to fetch the most relevant memories for this user. Passing current_message lets Remem use semantic search to surface memories most relevant to what the user just said.
4

Build the system prompt with memory

Format the returned memories as bullet points and inject them into the system prompt. If there are no memories yet, tell the agent this is a first conversation so it doesn’t fabricate context.
5

Call the LLM

Pass the memory-enriched system prompt and the user’s message to the model:
6

Save what the user told you

After responding, store the user’s message as an episodic memory. It will be available in all future sessions.

Complete Example

Here’s the full agent in a single file:

Test It Out

Run the script twice to see memory persistence in action. On the first run you introduce yourself:
On the second run, the agent remembers everything without being told again:
The agent never asked for your name, location, or preferences — it already knew.

Improving Your Agent

When the agent detects a key fact about the user, store it as semantic memory with high importance so it always surfaces in future sessions:
When a user corrects something, find the old memory and update it in place rather than storing a contradiction:
Session-specific context — like an order number the user is asking about — should expire automatically rather than cluttering long-term memory:

What’s Next

LangGraph Integration

Add persistent memory to a LangGraph agent with two extra nodes

Error Handling

Handle Remem errors gracefully so your agent never crashes in production

Store API

Full reference for the remember endpoint — all parameters and response fields

Context API

Full reference for the context endpoint — ranked memory retrieval