A simple LangChain starter with a FastAPI backend and modern chat UI interface.
# 1) Create & activate venv
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 2) Install dependencies
pip install -r requirements.txt
# 3) Configure OpenAI
cp .env.example .env
# Edit .env and set OPENAI_API_KEY
# 4) Run the backend server
python -m src.backend
# 5) Open your browser
# Visit http://localhost:8000 to use the chat interface
langchain-starter/
├── src/
│ ├── __init__.py
│ ├── agent.py # LangChain agent
│ └── backend.py # FastAPI server with chat endpoints
├── frontend/
│ ├── index.html # Chat interface
│ ├── styles.css # Modern UI styling
│ └── script.js # Frontend chat logic
├── requirements.txt # Python dependencies
└── README.md
GET /
- Serves the chat interfacePOST /api/chat
- Chat with the LangChain agentGET /api/health
- Health check endpoint
# Send a message to the agent
curl -X POST "http://localhost:8000/api/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Who are you?"}'
agent.py
— LangChain agentbackend.py
— FastAPI server with:- Chat endpoint for processing messages
- CORS middleware for frontend communication
- Static file serving for the chat interface
- Modern chat interface with:
- Real-time message exchange
- Typing indicators
- Responsive design
- Keyboard shortcuts
To add new tools to your agent, edit src/agent.py
:
# Backend with auto-reload
python -m src.backend
# Or using uvicorn directly
uvicorn src.backend:app --reload --host 0.0.0.0 --port 8000
- LangChain Documentation - Learn about LangChain
- FastAPI Documentation - Learn about FastAPI
- OpenAI API Documentation - Learn about OpenAI's API
- BuildKit Documentation - Learn about BuildKit
- Uses
langchain-openai
provider package (recommended modern setup) - FastAPI provides automatic API documentation at
/docs
- Frontend uses vanilla JavaScript (no framework dependencies)
- CORS enabled for development (configure for production)