A production-style conversational AI chatbot built with LangGraph, RAG, and Streamlit β featuring five backend variants from a simple LLM chat all the way to MCP-powered tool-using agents with persistent memory.
This repo is a fully functional chatbot application built in progressive layers. Each backend adds a new capability on top of the previous one β from a bare-bones LangGraph conversational agent to a RAG-powered document chatbot with MCP tool integration, SQLite persistence, real-time streaming, and threaded async UI.
Every backend has a paired Streamlit frontend so you can run and interact with each variant independently.
The project follows a clean backend / frontend separation:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit Frontend β
β (streamlit_frontend*.py / streamlit_rag_frontend.py) β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β calls
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ
β LangGraph Backend β
β (langgraph_backend.py / langgraph_*_backend.py) β
β β
β StateGraph βββΊ LLM Node βββΊ Tool/RAG/MCP Node β
β β β
β SqliteSaver (chatbot.db) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
rag-chatbot/
β
βββ π§ Backends (LangGraph agents)
β βββ langgraph_backend.py # Variant 1: Base conversational agent
β βββ langgraph_tool_backend.py # Variant 2: Agent with custom tools
β βββ langraph_rag_backend.py # Variant 3: RAG over documents
β βββ langgraph_database_backend.py # Variant 4: Persistent memory (SQLite)
β βββ langgraph_mcp_backend.py # Variant 5: MCP tool integration
β
βββ π₯οΈ Frontends (Streamlit UIs)
β βββ streamlit_frontend.py # UI for base agent
β βββ streamlit_frontend_tool.py # UI for tool-using agent
β βββ streamlit_rag_frontend.py # UI for RAG chatbot
β βββ streamlit_frontend_database.py # UI for persistent chatbot
β βββ streamlit_frontend_mcp.py # UI for MCP agent
β βββ streamlit_frontend_streaming.py # UI with token-by-token streaming
β βββ streamlit_frontend_threading.py # UI with threaded async execution
β
βββ ποΈ Database
β βββ chatbot.db # SQLite checkpoint store
β βββ chatbot.db-shm # Shared memory file (WAL mode)
β βββ chatbot.db-wal # Write-ahead log (WAL mode)
β
βββ requirements.txt
βββ .gitignore
Files: langgraph_backend.py + streamlit_frontend.py
A clean conversational agent built with LangGraph's MessagesState. Handles multi-turn chat with full message history maintained in graph state.
Stack: StateGraph Β· ChatOpenAI Β· MessagesState Β· MemorySaver
Files: langgraph_tool_backend.py + streamlit_frontend_tool.py
Extends the base agent with custom tool bindings. The LLM can decide when to invoke tools (web search, calculators, APIs, etc.) using a ReAct-style loop.
Stack: Tool node Β· ToolNode Β· bind_tools Β· conditional edges
Files: langraph_rag_backend.py + streamlit_rag_frontend.py
The core feature of this repo. Ingests documents, builds a FAISS vector index, and grounds every LLM response in retrieved context. Answers questions based on your own knowledge base.
User Query β Embed β FAISS Similarity Search β Retrieve Chunks β LLM β Answer
Stack: PyPDFLoader Β· RecursiveCharacterTextSplitter Β· OpenAIEmbeddings Β· FAISS Β· RetrievalQA
Files: langgraph_database_backend.py + streamlit_frontend_database.py
Adds SQLite-backed checkpointing so conversation state survives across sessions. Each conversation is tracked by a thread_id and can be resumed exactly where it left off.
Stack: SqliteSaver Β· chatbot.db (WAL mode) Β· thread_id config Β· state resumption
Files: langgraph_mcp_backend.py + streamlit_frontend_mcp.py
The most advanced variant. Integrates Model Context Protocol (MCP) β allowing the agent to connect to external MCP servers and use their tools dynamically. Enables filesystem access, API calls, browser automation, and more through a standardised protocol.
Stack: MCP client Β· dynamic tool discovery Β· LangGraph agent loop
| Frontend | Description |
|---|---|
streamlit_frontend.py |
Standard chat UI β input, output, message history |
streamlit_frontend_tool.py |
Shows tool calls and results inline in the chat |
streamlit_rag_frontend.py |
RAG UI with document upload and source attribution |
streamlit_frontend_database.py |
Session selector β load/resume past conversations |
streamlit_frontend_mcp.py |
MCP-connected UI with live tool status |
streamlit_frontend_streaming.py |
Real-time token-by-token streaming output |
streamlit_frontend_threading.py |
Async execution via threading β prevents UI blocking |
git clone https://github.com/codeantik/rag-chatbot.git
cd rag-chatbotpython -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install -r requirements.txtCreate a .env file in the root:
OPENAI_API_KEY=your_openai_api_key_here
LANGCHAIN_API_KEY=your_langsmith_api_key_here # optional, for tracing
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=rag-chatbotEach variant is run by pairing its backend with its frontend. Pick the variant you want:
# Variant 1 β Base chatbot
streamlit run streamlit_frontend.py
# Variant 2 β Tool-using agent
streamlit run streamlit_frontend_tool.py
# Variant 3 β RAG chatbot
streamlit run streamlit_rag_frontend.py
# Variant 4 β Persistent memory chatbot
streamlit run streamlit_frontend_database.py
# Variant 5 β MCP agent
streamlit run streamlit_frontend_mcp.py
# Streaming UI
streamlit run streamlit_frontend_streaming.py
# Threaded async UI
streamlit run streamlit_frontend_threading.pyThe corresponding backend is imported automatically by each frontend β no need to run them separately.
The chatbot.db SQLite file stores LangGraph checkpoints using WAL (Write-Ahead Logging) mode for concurrent read safety. The three files serve these roles:
| File | Role |
|---|---|
chatbot.db |
Main checkpoint database |
chatbot.db-shm |
Shared memory index for WAL |
chatbot.db-wal |
Pending write buffer |
To reset all conversation history:
rm chatbot.db chatbot.db-shm chatbot.db-wal| Package | Purpose |
|---|---|
langgraph |
Graph-based agent orchestration |
langchain |
Chains, prompts, retrievers |
langchain-openai |
OpenAI model integration |
langchain-community |
FAISS, document loaders, tools |
streamlit |
Interactive web UI |
faiss-cpu |
Vector similarity search for RAG |
pypdf |
PDF document loading |
openai |
Direct OpenAI API access |
python-dotenv |
Environment variable management |
- Base LangGraph conversational agent
- Tool-using ReAct agent
- RAG over documents (FAISS)
- SQLite persistent memory
- MCP tool integration
- Token streaming UI
- Threaded async UI
- Multi-document upload support
- User authentication & multi-user sessions
- Deploy to Streamlit Cloud / Docker
Ankit Singh β Full Stack Developer & Agentic AI Specialist
Also check out the foundational learning repos:
- π codeantik/langsmith β LangChain & RAG fundamentals
- πΈοΈ codeantik/langgraph β LangGraph patterns & workflows
This project is open source and available under the MIT License.