A conversational AI agent for UK train information. Built with LangChain, Flask, React, and SQLite.
LangChain has changed quite a bit over the past year, so, in order to "stay current" with how LangChain is used, I decided to build this project as a tech demo and learning (or refresher) exercise.
- Live UK train departures and schedules
- TfL (Transport for London) status information
- Ticket fare information (estimates only)
- Natural language date/time understanding (e.g. "tomorrow at 3pm" etc.)
- LangChain: Utilizes GPT-4o* with custom tools (these tools help with station lookups, live departures, fare estimates, and TfL status)
- Station Database: 2,598+ UK stations (Data Source)
- Selenium: Used for scraping some information
- Conversation Storage: Full conversation history with snowflake IDs
- REST API: Endpoints for chat, conversations, and management
*This can be easily swapped out for other LLMs supported by LangChain - I was lazy and had some OpenAI credits to burn.
- ChatGPT-style UI: Modern and clean interface with icons from Lucide Icons
- Markdown Support: Rich formatting for agent responses
- Dark Mode: Persistent theme preference
Rename the .env.example file in the backend directory to .env and fill in your OpenAI API key and Realtime Trains credentials:
OPENAI_API_KEY=your_openai_api_key_here
RTT_USERNAME=your_rtt_username
RTT_PASSWORD=your_rtt_passwordcd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
# Install dependencies
uv pip install -r requirements.in
# Initialize database (creates single SQLite database with all tables and loads the station data)
python src/init_db.py
# Run server
python app.pyBackend runs on http://localhost:5000
cd frontend
# Install dependencies
npm install
# Run dev server
npm run devFrontend runs on http://localhost:5174 (or similar)
Try these queries:
- "What trains are leaving from London Waterloo?"
- "Show me trains from Birmingham New Street to London Euston"
- "Are there any delays on the Metropolitan line?"
You can even ask follow-up questions:
- "When is the next train to Guildford?" (after asking about Waterloo)
- "How much is a return ticket for this train?" (after asking about trains from Birmingham to London)
- "What lines are currently disrupted on the TfL network?" (after asking about delays)
And you can even use natural language for date/time queries:
- "Show me trains from Reading tomorrow"
- "Trains from Paddington next Monday morning"
- "What trains are there from London Victoria to Manchester at 3pm?"
- UK Station Data: davwheat/uk-railway-stations*
- Realtime Train Data: realtimetrains.co.uk
- Ticket Fare Data: brfares.com
- TfL Status Data: tfl.gov.uk
*derived from Trainline EU's data repository where the UK data is derived from official National Rail data.
MIT




