This project implements a conversational agent (chatbot) using Langgraph, a library built on top of LangChain for creating robust and stateful multi-turn applications. The agent maintains context across conversations and demonstrates core principles for building interactive AI assistants.
- 🐍 Python 3.12+
- 🔑 OpenAI API key (or compatible API provider)
- 📦 Git
git clone https://github.com/arnabd64/Chatbot-Langgraph.git
cd Chatbot-LanggraphCreate a .env file in the project root:
# Required
OPENAI_API_KEY="your-openai-api-key-here"
MODEL_NAME="gpt-4o-mini"
# Optional - for OpenAI compatible providers
OPENAI_API_BASE=""
# Optional - for Langsmith tracing
LANGSMITH_TRACING=true
LANGSMITH_PROJECT="Langgraph"
LANGSMITH_ENDPOINT="https://api.smith.langchain.com"
LANGSMITH_API_KEY="your-langsmith-api-key-here"Choose one of the following methods:
# Create and activate virtual environment
python -m venv .venv
# Activate environment
source .venv/bin/activate # Linux/macOS
# OR
.venv\Scripts\activate # Windows
# Install dependencies
pip install -e .
# Run the server
python main.py# Install dependencies
uv sync
# Run the server
uv run python main.pyRequires Visual Studio Code with Dev Containers extension:
- Open VS Code:
code . - Press
F1and search for "Dev Containers: Rebuild and Reopen in Dev Containers" - Run:
uv run python main.py
- 🌐 Web Interface: Visit
http://localhost:8000/app - 📖 API Documentation: Visit
http://localhost:8000/docs
Each chat session requires a unique session ID:
curl -X GET "http://localhost:8000/chat/id" -H "accept: text/plain"Response:
dbaed28e-cf61-457a-b034-2bd48ab5424a
Send messages using the session ID:
curl -X POST "http://localhost:8000/chat/dbaed28e-cf61-457a-b034-2bd48ab5424a" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '[
{
"role": "human",
"content": "Hi"
}
]'Response:
{
"error": "false",
"data": [
{
"role": "human",
"content": "Hi"
},
{
"role": "ai",
"content": "Hello! How can I assist you today?"
}
]
}Each message is a JSON object with:
role: Message sender ("system", "human", or "ai")content: Message text
- 🔄 Stateful Conversations: Maintains context across multiple turns
- 🛠️ FastAPI Integration: REST API for easy integration
- 🌐 Web Interface: Built-in chat interface
- 🔒 Session Management: Isolated chat sessions using UUIDs
- 🔧 OpenAI Compatible: Works with OpenAI and compatible providers
- 📊 Langsmith Integration: Optional tracing and monitoring