LangChain + LangGraph chatbot with persistent memory powered by RetainDB.
Memories survive server restarts and new sessions. The LangGraph agent retrieves relevant context before each reply and stores every turn for future recall.
- LangChain + LangGraph — agent orchestration
- OpenAI
gpt-4o-mini— chat completions - RetainDB — persistent memory (direct REST calls)
- FastAPI — HTTP interface
# 1. Clone
git clone https://github.com/Alinxus/retaindb-langchain-starter
cd retaindb-langchain-starter
# 2. Install
pip install -r requirements.txt
# 3. Configure
cp .env.example .env
# Edit .env with your keys
# 4. Run
uvicorn main:app --reloadcurl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"user_id": "alice", "message": "I am building a SaaS in Python"}'{ "reply": "That's exciting! What kind of SaaS are you building?" }After a server restart:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"user_id": "alice", "message": "What do you know about me?"}'{ "reply": "You're building a SaaS in Python!" }POST /chat
│
├─► LangGraph agent node
│ ├─► POST /v1/context/query ──► RetainDB retrieves relevant memories
│ ├─► ChatOpenAI gpt-4o-mini (memories in system prompt)
│ └─► POST /v1/learn ──► Stores the turn for future sessions
│
└─► Returns reply
retaindb-langchain-starter/
├── agent.py # LangGraph graph + RetainDB memory functions
├── main.py # FastAPI app
├── requirements.txt
├── .env.example
└── README.md
| Variable | Description |
|---|---|
RETAINDB_API_KEY |
Get free at retaindb.com |
OPENAI_API_KEY |
Get at platform.openai.com |
- retaindb-nextjs-starter — Next.js + Vercel AI SDK
- retaindb-python-starter — FastAPI + OpenAI
- retaindb-express-starter — Express.js + Vercel AI SDK