# LangGraph Chatbot
A stateful conversational AI application built with LangGraph, LangChain, and Streamlit. The application provides a clean chat interface with conversation threads, message history, and streaming AI responses.
## Overview
This project demonstrates how to build a conversational AI application using LangGraph for workflow and state management, LangChain for LLM integration, and Streamlit for the frontend interface.
The application supports multiple independent conversations, allowing users to create new chats and switch between existing conversation threads.
## Features
- Stateful conversations using LangGraph
- Multiple independent conversation threads
- Conversation history
- Streaming AI responses
- Interactive Streamlit interface
- New conversation creation
- Modular backend architecture
- LLM integration through LangChain
- Environment-based API configuration
## Architecture
```text
┌─────────────────────┐
│ Streamlit │
│ UI │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Chat Controller │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ LangGraph │
│ State / Workflow │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ LangChain │
│ LLM Interface │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ LLM │
└─────────────────────┘The application is divided into two primary layers:
The Streamlit interface handles:
- User input
- Displaying messages
- Conversation selection
- Creating new conversations
- Rendering streamed responses
The backend uses LangGraph to manage:
- Conversation state
- Message flow
- LLM execution
- Thread-based conversations
- Streaming responses
Each conversation is assigned a unique thread ID.
Thread 1
│
├── User Message
├── AI Response
├── User Message
└── AI Response
Thread 2
│
├── User Message
└── AI Response
This keeps conversations independent and allows users to switch between different conversations without mixing their message history.
The application supports streaming AI responses.
Instead of waiting for the entire response to be generated, the response is progressively displayed in the Streamlit interface.
User Message
│
▼
LangGraph Workflow
│
▼
LLM Generation
│
▼
Streaming Response
│
▼
Streamlit UI
Chatbot/
│
├── .gitignore
├── chatbot.ipynb
├── code.py
├── requirements.txt
├── streaming.py
├── threading.py
├── ui.py
└── README.md
| File | Description |
|---|---|
ui.py |
Streamlit frontend and chatbot interface |
threading.py |
Conversation thread management |
streaming.py |
Streaming chatbot responses |
code.py |
Core chatbot implementation |
chatbot.ipynb |
Notebook for experimentation and development |
requirements.txt |
Project dependencies |
.gitignore |
Files and directories excluded from Git |
| Technology | Purpose |
|---|---|
| Python | Application development |
| LangGraph | State management and workflow orchestration |
| LangChain | LLM integration |
| Streamlit | Web-based user interface |
| Jupyter Notebook | Experimentation and development |
Make sure the following are installed:
- Python 3.10 or higher
- pip
- Git
git clone https://github.com/ANNON17-byte/Chatbot.gitcd Chatbotpython -m venv venvActivate the environment:
venv\Scripts\activatepython3 -m venv venvActivate the environment:
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory.
Add the required API credentials for your LLM provider.
Example:
API_KEY=your_api_key_hereDo not commit the .env file or API keys to GitHub.
Start the Streamlit application:
streamlit run ui.pyThe application will normally be available at:
http://localhost:8501
- Start the Streamlit application.
- Open the application in your browser.
- Enter a message in the chat input.
- Send the message to the chatbot.
- The response will be streamed to the interface.
- Create a new chat using the New Chat button.
- Switch between conversations using the conversation history.
User:
Explain what LangGraph is.
AI:
LangGraph is a framework for building stateful,
multi-step applications with LLMs...
User
│
▼
Streamlit Interface
│
▼
Thread Identification
│
▼
LangGraph
│
▼
LLM
│
▼
Streaming Response
│
▼
Streamlit UI