A comprehensive Python-based travel booking system that combines a modern Streamlit web interface with an intelligent agent capable of executing functions through REPL (Read-Eval-Print Loop) based on natural language input. This system demonstrates the integration of Natural Language Inference (NLI) with database operations, dynamic pricing algorithms, and a complete booking workflow.
AgentRepl/
โโโ ๐ WEB APPLICATION
โ โโโ streamlit_app.py # Main Streamlit web application
โ โโโ run_app.bat # Windows batch launcher
โ โโโ run_app.py # Python application launcher
โ
โโโ ๐ค AI AGENT & CORE
โ โโโ agent_repl.py # AI agent with NLI parsing
โ โโโ fetch_and_calculate.py # Core booking calculation functions
โ โโโ test_agent.py # Agent testing utilities
โ
โโโ ๐ผ BOOKING & MANAGEMENT
โ โโโ booking.py # Interactive booking system
โ โโโ admin.py # Administrative functions
โ โโโ add_route.py # Route management utility
โ โโโ update_discount.py # Discount management
โ
โโโ ๐ DATABASE UTILITIES
โ โโโ view_db.py # Database viewer utility
โ โโโ check_db.py # Database validation tool
โ โโโ travel.db # SQLite database file
โ
โโโ ๐ CONFIGURATION & DOCS
โ โโโ requirements.txt # Python dependencies
โ โโโ README.md # Project documentation
โ โโโ db_output.txt # Database state export
โ
โโโ ๐ฆ CACHE
โโโ __pycache__/ # Python cache files
โโโ agent_repl.cpython-*.pyc
โโโ booking.cpython-*.pyc
โโโ fetch_and_calculate.cpython-*.pyc
โโโ streamlit_app.cpython-*.pyc
๐ก How it works: Natural language gets translated into executable Python functions through an intelligent REPL agent!
The system follows this execution flow:
User says: "total price for user nikitha" โ ๐ READ
โ
agent_repl.py: Translates to โ Complex SQL + fetch_and_explain_booking() calls โ โ๏ธ EVAL
โ
REPL executes: Generated Python code with database queries โ โก EVAL
โ
fetch_and_calculate.py: Called multiple times for each booking calculation โ ๐ EVAL
โ
Returns: Route-wise summary + total price โ ๐ PRINT
โ
Ready for next natural language command โ ๐ LOOP
๐ Visual Guide: See how user commands flow through the system layers below!
flowchart TD
%% User Interface Layer
USER[๐ค User Input<br/>Web Browser/CLI]
WEB_UI[๐ Web Interface<br/>Streamlit Dashboard]
CHAT[๐ฌ Chat Interface<br/>Booking Assistant]
TERMINAL[๐ป CLI Output<br/>Terminal Responses]
%% Core Processing Engine
STREAMLIT_APP[๐ Streamlit App<br/>streamlit_app.py]
AGENT[๐ค Agent REPL<br/>agent_repl.py]
NLI[๐ง NLI Parser<br/>Regex Pattern Matching]
REPL[โก REPL Engine<br/>Execution Handler]
%% Business Logic Layer
CORE[๐ Core Functions<br/>fetch_and_calculate.py]
PRICING[๐ฐ Pricing Engine<br/>Dynamic Calculations]
VALIDATION[๐ Input Validation<br/>Security Checks]
BOOKING_LOGIC[๐ซ Booking Logic<br/>Multi-step Workflow]
%% Data Layer
DATABASE[(๐๏ธ SQLite Database<br/>travel.db)]
USERS[(๐ฅ Users Table<br/>Authentication & Loyalty)]
ROUTES[(๐ฃ๏ธ Routes Table<br/>Pricing & Capacity)]
BOOKINGS[(๐ซ Bookings Table<br/>Reservations)]
DISCOUNTS[(๐ธ Discounts Table<br/>Rules & Offers)]
%% Supporting Systems
BOOKING[๐ CLI Booking<br/>booking.py]
ADMIN[๐ง Admin Panel<br/>admin.py]
VIEWER[๐ Database Viewer<br/>view_db.py]
DISCOUNT_MGR[๐ณ Discount Manager<br/>update_discount.py]
ROUTE_MGR[๐ฃ๏ธ Route Manager<br/>add_route.py]
CHECKER[๐ Database Checker<br/>check_db.py]
LAUNCHER[๐ App Launcher<br/>run_app.bat/.py]
%% PRIMARY WEB INTERFACE FLOW
USER --> LAUNCHER
LAUNCHER --> STREAMLIT_APP
STREAMLIT_APP --> WEB_UI
STREAMLIT_APP --> CHAT
STREAMLIT_APP --> ADMIN
%% CHAT BOOKING FLOW
CHAT --> BOOKING_LOGIC
BOOKING_LOGIC --> VALIDATION
VALIDATION --> PRICING
PRICING --> DATABASE
%% REPL INTEGRATION FLOW
CHAT --> AGENT
AGENT --> NLI
NLI --> REPL
REPL --> CORE
CORE --> DATABASE
%% CLI ALTERNATIVE FLOW
USER --> AGENT
AGENT --> TERMINAL
USER --> BOOKING
USER --> ADMIN
%% DATABASE CONNECTIONS
DATABASE --> USERS
DATABASE --> ROUTES
DATABASE --> BOOKINGS
DATABASE --> DISCOUNTS
%% SUPPORTING SYSTEM CONNECTIONS
STREAMLIT_APP --> DATABASE
BOOKING --> DATABASE
ADMIN --> DATABASE
VIEWER --> DATABASE
DISCOUNT_MGR --> DISCOUNTS
ROUTE_MGR --> ROUTES
CHECKER --> DATABASE
%% RESPONSE FLOWS
DATABASE --> PRICING
PRICING --> CHAT
CORE --> TERMINAL
BOOKING_LOGIC --> CHAT
%% Styling
classDef userLayer fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
classDef webLayer fill:#f093fb,stroke:#333,stroke-width:2px,color:#fff
classDef processingLayer fill:#43e97b,stroke:#333,stroke-width:2px,color:#fff
classDef businessLayer fill:#ffeaa7,stroke:#333,stroke-width:2px,color:#333
classDef dataLayer fill:#fa709a,stroke:#333,stroke-width:2px,color:#fff
classDef supportLayer fill:#ffecd2,stroke:#333,stroke-width:2px,color:#333
class USER userLayer
class WEB_UI,CHAT,STREAMLIT_APP webLayer
class AGENT,NLI,REPL,TERMINAL processingLayer
class CORE,PRICING,VALIDATION,BOOKING_LOGIC businessLayer
class DATABASE,USERS,ROUTES,BOOKINGS,DISCOUNTS dataLayer
class BOOKING,ADMIN,VIEWER,DISCOUNT_MGR,ROUTE_MGR,CHECKER,LAUNCHER supportLayer
Viewing Options:
- ๐ฏ GitHub Native: The flowchart above renders directly on GitHub
- ๐ฅ๏ธ Enhanced HTML: Open
architecture_flowchart.htmlfor interactive version with custom styling
The system is organized into 6 distinct layers:
- ๐ต User Interface Layer: Handles user input through web browser or command line
- ๐ฃ Web Application Layer: Streamlit interface with chat, admin panel, and dashboard
- ๐ข Processing Layer: NLI parsing, REPL execution, and command processing
- ๐ก Business Logic Layer: Core functions, pricing algorithms, validation, and booking workflow
- ๐ด Data Layer: Database operations and data storage across multiple tables
- ๐ค Support Systems: Administrative tools, utilities, and launchers
๐ง Core Engine: Each component serves a specific purpose in the travel booking ecosystem!
- streamlit_app.py: Modern web application with chat interface, admin panel, and booking system
- agent_repl.py: AI agent with regex-based NLI parsing that translates natural language to executable Python functions
- fetch_and_calculate.py: Core booking calculation engine with dynamic pricing algorithms
- booking.py: Interactive CLI booking system for creating new reservations
- admin.py: Administrative interface for system management
- add_route.py: Route management utility for adding and updating travel routes
- update_discount.py: Discount management system for creating and modifying discount rules
- check_db.py: Database validation and integrity checking tool
- test_agent.py: Testing utilities for agent functionality validation
- run_app.bat: Windows batch file for easy application startup
- run_app.py: Python launcher script for cross-platform compatibility
- view_db.py: Database viewer utility that exports current state to db_output.txt
- travel.db: SQLite database containing:
- users: User accounts with loyalty points, authentication, and session data
- routes: Travel routes with pricing, capacity, transport types, and real-time availability
- bookings: Individual booking records with calculated prices, timestamps, and status
- discounts: Dynamic discount rules based on user types, loyalty points, and special offers
๐ Database Magic: Our SQLite database efficiently handles thousands of bookings with lightning-fast queries!
- requirements.txt: Python dependencies including Streamlit for web interface
- db_output.txt: Current database state export for quick reference
- travel.db: Main SQLite database with users, routes, bookings, and discounts tables
๐ Amazing Capabilities: From natural language queries to dynamic pricing - this system does it all!
- Streamlit Web App: Complete travel booking system with professional UI
- Chat-based Booking: Conversational interface for natural booking experience
- Real-time Pricing: Dynamic price calculation with instant feedback
- Admin Dashboard: Web-based administration with database management
- User Authentication: Secure login system with session management
- Discount System: Advanced discount application with loyalty points
- Booking Queries: "show booking 9", "explain booking 5"
- User Totals: "total price for user nikitha", "all bookings for John"
- Multiple Bookings: "calculate bookings 1,2,3", "show bookings 5 to 8"
- Ownership Checks: "who owns booking 7", "booking owner 3"
- General Queries: "show all bookings", "list all users"
- Demand-based pricing: Prices increase as seats fill up
- Loyalty discounts: Based on user loyalty points
- Child discounts: 50% discount for child travelers
- Real-time calculations: Prices calculated at booking time
๐ค Money Talks: Our dynamic pricing ensures fair rates while maximizing revenue - it's a win-win for everyone!
- Smart Route Search: Intelligent origin/destination matching
- Dynamic Seat Management: Real-time availability tracking
- Multi-step Booking: Guided process from login to confirmation
- Traveller Type Selection: Adult/child pricing with automatic discounts
- Payment Processing: Final price calculation with all applicable discounts
- Case-sensitive matching: Exact username matching (Nikitha โ nikitha)
- Loyalty point system: Points affect discount eligibility
- Multiple user types: Adult/child pricing tiers
- Session Management: Secure authentication with state persistence
- Auto Account Creation: Seamless user registration during first login
- Local Mode: Direct function execution with Python exec()
- System Mode: External process execution via subprocess
- Interactive Mode: Full Python shell integration
- Web Integration: Seamless REPL functionality within Streamlit interface
๐ Flexibility at its Best: Choose the execution mode that fits your needs - from quick local runs to full system integration!
๐ Data Structure: Well-organized tables with proper relationships for optimal performance!
CREATE TABLE users (
id INTEGER PRIMARY KEY,
username TEXT UNIQUE,
password_hash TEXT,
loyalty_points INTEGER DEFAULT 0
);CREATE TABLE routes (
id INTEGER PRIMARY KEY,
origin TEXT,
destination TEXT,
departure_time TEXT,
base_price REAL,
seats_total INTEGER,
transport_type TEXT
);CREATE TABLE bookings (
id INTEGER PRIMARY KEY,
user_id INTEGER,
route_id INTEGER,
seat_number TEXT,
price_paid REAL,
booking_time TEXT,
status TEXT DEFAULT 'confirmed',
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (route_id) REFERENCES routes(id)
);๐ Relationships Done Right: Foreign keys ensure data integrity while keeping everything perfectly organized!
๐ Get Started: Ready to see the magic in action? Try these examples!
๐ Two Ways to Experience: Choose between the modern web interface or traditional CLI tools!
๐ฏ One-Click Launch - Windows Users:
# Double-click the batch file or run in terminal
run_app.bat๐ฏ Cross-Platform Launch:
# Python launcher (works on all platforms)
python run_app.pyโจ What you get:
- ๐ Automatic Streamlit Startup - Opens web app at
http://localhost:8501 - ๐ซ Complete Booking System - Chat interface with natural language processing
- ๐ Admin Dashboard - Database setup, user management, route creation
- ๐งฎ REPL Calculator - AI agent with enhanced web formatting
- ๐จ Professional UI - Modern design with excellent user experience
๐ฏ Traditional Streamlit Setup:
# Install dependencies
pip install streamlit
# Run the web application
streamlit run streamlit_app.py๐ฏ Access: Open your browser to http://localhost:8501 and enjoy the full experience!
โ ๏ธ Setup Order: Runpython admin.pyfirst to populate database, then use other tools!
python admin.py
# Creates users, routes, and sample bookings# Create new bookings interactively
python booking.py
# Add new routes to the system
python add_route.py
# Manage discount rules
python update_discount.py
# Check database integrity
python check_db.py
# View current database state
python view_db.pypython agent_repl.py
# Natural language queries:
# - "show booking 1"
# - "total for nikitha"
# - "who owns booking 5"python test_agent.py
# Validate agent functionality and test various scenarios๐ก Pro Tip: The web interface (
run_app.batorstreamlit_app.py) provides all CLI functionality with a much better user experience!
๐ฌ You: show booking 9
๐ค Agent: [Displays detailed booking calculation]
๐ฌ You: show all bookings under user nikitha
๐ค Agent: [Shows detailed breakdown for user 'nikitha']
๐ฌ You: total price for user nikitha
๐ค Agent: [Shows route-wise summary and total]
๐ฌ You: who owns booking 5
๐ค Agent: [Shows "Booking 5 โ User: [username]"]
๐ฌ You: calculate bookings 1,2,3
๐ค Agent: [Shows individual and combined totals]
๐ฏ Live Demo: Here's exactly what happens when you interact with the agent!
$ python agent_repl.py
๐ค TravelBookingAgent initialized with LOCAL REPL execution.
๐ฌ You: show booking 9
๐ค Agent executing in LOCAL REPL: result = fetch_and_explain_booking(9)
============================================================
Booking ID: 9
Route: chennai -> london (flight)
Base price: 65000.0
Seats total: 3
Seats left at booking: 3
--- Calculation Details ---
Demand factor = 1 + (1 - seats_left / seats_total) * 0.5
= 1 + (1 - 3 / 3) * 0.5
= 1 + (0.00) * 0.5
= 1.00
Price after demand = base_price * demand_factor
= 65000.0 * 1.00
= 65000.0
Discount applied = 50.0%
Final price = price_after_demand * (1 - discount/100)
= 65000.0 * (1 - 50.0/100)
= 32500.0
--------------------------
Traveller type: adult
User loyalty points: 0
Final price paid: 32500.0
Price recorded in booking: 32500.0
Booking time: 2025-08-01T20:47:40.938888
Status: confirmed
============================================================
โ
LOCAL REPL execution completed. Result: 32500.0
๐ค Result: 32500.0
๐ฌ You: total price for user nikitha
๐ค Agent executing in LOCAL REPL: fetch_all_bookings_for_user("nikitha")
============================================================
๐ ROUTE-WISE SUMMARY FOR USER 'nikitha':
==================================================
Route delhi -> paris: 618750.0
Route bengaluru -> usa: 57750.0
Route vij -> hyd: 1575.0
------------------------------
๐ฏ TOTAL FOR nikitha: 678075.0
==================================================
โ
LOCAL REPL execution completed. Result: 678075.0
๐ค Result: 678075.0
๐ฌ You: who owns booking 1
๐ค Agent executing in LOCAL REPL: [ownership query code]
============================================================
๐ BOOKING OWNERSHIP DETAILS:
Booking ID: 1
Owner: Nikitha (User ID: 1)
Route: vijayawada -> paris
Price Paid: 12000.5
Booking Time: 2025-07-30T17:41:17.425869
Status: confirmed
============================================================
โ
LOCAL REPL execution completed.
๐ฌ You: exit
๐ Goodbye!๐ฏ Seamless Experience: Watch how naturally the agent understands and responds to your requests!
# View current database state
python view_db.py
# Interactive booking system
python booking.py
# Administrative functions
python admin.py๐ช Explore More: The agent understands many different ways to ask for information!
๐ฌ You: calculate bookings 2,3,4
๐ค Agent: [Shows each booking individually plus total sum]
๐ฌ You: show bookings 5 to 8
๐ค Agent: [Displays bookings 5, 6, 7, and 8 with calculations]
๐ฌ You: all bookings for John
๐ค Agent: [Lists all bookings and totals for user 'John']
๐ฌ You: total for NIKITHA
๐ค Agent: [Case-sensitive search for exact username 'NIKITHA']
๐ฌ You: show me all bookings under nikitha
๐ค Agent: [Shows detailed breakdown for user 'nikitha']
๐ฌ You: show all bookings
๐ค Agent: [Lists all bookings in the system]
๐ฌ You: list all users
๐ค Agent: [Shows all registered users]
๐ฌ You: help
๐ค Agent: [Displays available commands and examples]
๐ฌ You: total for nonexistent_user
๐ค Agent: No users found with EXACT name 'nonexistent_user' (case sensitive)
๐ฌ You: show booking 999
๐ค Agent: No booking found with ID 999
๐ฌ You: random invalid command
๐ค Agent: โ I don't understand that command. Type 'help' for available commands.
๐ก Smart Pricing: Advanced algorithms that factor in demand, loyalty, and user types!
The system uses a sophisticated pricing model:
- Base Price: Set per route
- Demand Factor:
1 + (1 - seats_left/seats_total) * 0.5 - Child Discount: 50% off for child travelers
- Loyalty Discount: Based on user points and discount rules
- Final Price:
base_price * demand_factor * (1 - discount/100)
๐ Award-Winning Algorithm: Our pricing engine adapts in real-time to market conditions and user behavior!
๐ฏ Quick Start: Get up and running in minutes with these simple steps!
- Python 3.7+
- SQLite3 (built-in with Python)
- Web browser (for Streamlit interface)
# Clone the repository
git clone <repository-url>
cd AgentRepl
# Install dependencies
pip install -r requirements.txt
# One-click launch (Windows)
run_app.bat
# OR Cross-platform launch
python run_app.py
# OR Manual Streamlit launch
streamlit run streamlit_app.py# Step 1: Initialize database
python admin.py
# Step 2: Start AI agent
python agent_repl.py- ๐ Web Interface: Complete booking system at
http://localhost:8501 - ๐ค AI Chat: Natural language booking with intelligent responses
- ๐ Admin Panel: Database management through web interface
- ๐ป CLI Tools: Traditional command-line access to all features
๐ค AI Understanding: The agent recognizes these natural language patterns automatically!
The agent recognizes these natural language patterns:
| Pattern | Example | Function Called |
|---|---|---|
| Booking by ID | "show booking 5" | fetch_and_explain_booking(5) |
| User totals | "total for nikitha", "show all bookings under user nikitha" | fetch_all_bookings_for_user("nikitha") |
| Multiple bookings | "bookings 1,2,3" | Multiple fetch_and_explain_booking() calls |
| Ownership | "who owns booking 7" | Booking ownership query |
| All bookings | "show all bookings" | Complete booking list |
๐ Intelligence Unleashed: The more you use it, the more you'll appreciate how smart this system really is!
โก Powerful Engine: Built with cutting-edge technologies for optimal performance!
- Regex-based NLI: Sophisticated pattern matching for natural language understanding
- Context-aware responses: Intelligent conversation flow with memory retention
- Multi-intent recognition: Handles complex queries with multiple requirements
- Error recovery: Graceful handling of invalid inputs with helpful suggestions
- Streamlit Framework: Modern, responsive web interface
- Real-time updates: Live data synchronization across all components
- Session management: Secure user authentication with persistent state
- Cross-platform compatibility: Works on Windows, macOS, and Linux
- SQLite integration: Lightweight, serverless database with ACID transactions
- Case-sensitive user lookup: Exact string matching for user identification
- Multi-line code execution: Uses
exec()for complex operations - Real-time calculations: Live pricing based on current database state
- Data integrity: Foreign key constraints and validation checks
- Modular design: Separate components for different functionalities
- Plugin architecture: Easy to add new commands and functions
- Multiple execution modes: Local, system, and interactive REPL options
- Comprehensive testing: Built-in test suite for reliability validation
๐ Modern Web Experience: Complete travel booking system with chat-based AI assistant!
The system features a comprehensive Streamlit web application that provides all functionality through an intuitive, conversational interface.
- Natural Conversation Flow: Chat with AI assistant for booking tickets
- Smart Login System: Guided username/password authentication
- Origin/Destination Intelligence: Automatic route matching and suggestions
- Real-time Route Search: Instant availability and pricing updates
- Dynamic Discount Application: Automatic discount selection with loyalty points
- Complete Booking Workflow: From login to confirmation in a single chat
- Booking History Access: View all user bookings through chat commands
- Database Setup: Initialize users, routes, and sample data
- User Management: Create accounts, reset passwords, manage loyalty points
- Route Management: Add new routes with pricing and capacity settings
- Discount Rules: Create and modify discount policies
- System Monitoring: Database integrity checks and status reports
- Web-based AI Agent: All agent_repl.py functionality in the browser
- Enhanced Output Formatting: Color-coded results with professional styling
- Natural Language Queries: Same powerful NLI parsing as CLI version
- Visual Data Presentation: Clear separation of booking details and calculations
-
Quick Launch
# Windows users (one-click) run_app.bat # Cross-platform python run_app.py # Manual Streamlit streamlit run streamlit_app.py
-
Access the Interface
- Open browser to
http://localhost:8501 - Choose your preferred interface mode
- Start booking tickets through natural conversation!
- Open browser to
User: hello
Bot: Welcome! I'm your travel assistant...
User: login
Bot: What's your username?
User: teja
Bot: Now, what's your password?
User: teja@12
Bot: Welcome back! Where will you be traveling from?
User: goa
Bot: Starting from Goa. Where would you like to go?
User: usa
Bot: Perfect! I found 1 route from Goa to USA:
1. Goa โ USA (flight) - $54,000.00
Just type '1' to book this route!
User: 1
Bot: Great! Please choose traveller type:
- Type 'adult' for adult ticket
- Type 'child' for child ticket (50% discount)
User: adult
Bot: You qualify for discounts! Choose your preferred discount:
1. Student Discount - Save 50%!
2. Senior Citizen - Save 40%!
...
User: 1
Bot: Final price: $27,675.00 with Student Discount
Type 'confirm' to complete booking
User: confirm
Bot: ๐ Booking successful! Booking ID: 18
Your journey from Goa โ USA is confirmed!
User: show my bookings
Bot: [Displays complete booking history with calculations]
User: total price for teja
Bot: [Shows route-wise summary and total spending]
- Professional Styling: Clean, modern design with excellent readability
- Responsive Design: Seamless experience across all device sizes
- Color-Coded Responses: Visual hierarchy for different types of information
- Session Persistence: Maintains user login and booking context
- Error Handling: Intelligent error recovery with helpful suggestions
- Multi-language Support: Natural language understanding with flexible phrasing
The web interface maintains full compatibility with all CLI features while providing an enhanced user experience through modern web technologies and conversational AI.
๐ Join the Journey: This project showcases the future of AI-powered travel booking systems!
This project demonstrates the integration of:
- Natural Language Processing: Advanced regex-based NLI parsing
- Conversational AI: Context-aware chat interfaces with memory retention
- Modern Web Development: Streamlit-based responsive applications
- Database Operations: SQLite integration with ACID transactions
- Dynamic Pricing Algorithms: Real-time demand-based calculations
- REPL-based Execution: Code generation and execution from natural language
- User Experience Design: Intuitive chat-based booking workflows
- NLP Models: Integrate transformer models for better language understanding
- Payment Integration: Add real payment gateway connections
- External APIs: Connect with airline/hotel booking systems
- Mobile App: React Native or Flutter mobile interface
- Advanced Analytics: User behavior tracking and business intelligence
- Multi-language Support: Internationalization and localization
- Command Patterns: Extend regex patterns for more natural language variants
- Pricing Rules: Add seasonal pricing, route-specific discounts, and demand surge pricing
- Integration APIs: Connect with external travel services and real-time data feeds
- Testing Suite: Comprehensive test coverage for all booking scenarios
- Performance Optimization: Database indexing and query optimization
- Security Enhancements: Advanced authentication and data encryption
Feel free to contribute by extending functionality, improving the user experience, or adding new features to this AI-powered travel booking ecosystem.
๐ Happy Coding: Thank you for exploring our AI-powered travel booking system! May your journey with this code be as amazing as the destinations it helps book!