Kavak Technical Case Study Implementation
An intelligent travel assistant built with LangGraph and FastAPI that helps users plan international travel through natural language interactions. This project demonstrates advanced prompt engineering, RAG implementation, and conversational AI capabilities.
- Natural Language Flight Search: Handle queries like "Find me a round-trip to Tokyo in August with Star Alliance airlines only"
- Intelligent Query Processing: Extract and search criteria from conversational input
- Advanced Flight Filtering: Support for airline alliances, layover preferences, price ranges, and refundability
- RAG-Powered Knowledge Base: Answer visa requirements and travel policy questions
- LangGraph Agent Orchestration: Tool routing and context management
- Streaming Responses: Real-time conversation experience
- Session Management: Persistent conversation context
- Vector Search: FAISS-based semantic search for flights and travel information
- Multi-format Data Processing: JSON flight data and markdown/text knowledge bases
- Prompt Engineering: Sophisticated system prompts for travel-specific interactions
- Tool Integration: Modular tool architecture for extensibility
- Docker Support: Containerized deployment
- Create and activate a virtual environment:
python3 -m venv env
source env/bin/activate # On Windows: .\env\Scripts\activate
- Set up environment variables:
cd api
cp .env.example .env
# Edit .env file and add your API keys and configurations
- Install dependencies:
pip install -r requirements.txt
- Run the backend server:
python -m uvicorn app:app --host 0.0.0.0 --port 8000 --reload
The backend will be available at http://localhost:8000
Or use any other static file server of your choice.
The application is containerized using Docker and orchestrated with Docker Compose.
- Docker
- Docker Compose
- Set up environment variables:
cd api
cp .env.example .env
# Edit .env file with your API keys and configurations
cd ..
- Build and start the containers:
docker compose up --build
- Access the application:
- Backend API: http://localhost:8000
- Backend:
- Local development: Port 8000
- Docker: External port 8000, internal port 8000
- LangGraph Orchestration: State management and tool routing
- Tool Integration: Modular tools for flight search and knowledge retrieval
- Memory Management: Conversation context with configurable memory size
- Streaming Interface: Real-time response generation
- Query Parsing: Natural language understanding and intent extraction
- Criteria Normalization: Convert conversational input to structured search parameters
- Multi-Source Search: Vector search across flight data and knowledge base
- Result Synthesis: Formatting of results
- Context Management: Maintain conversation state and preferences
- Knowledge Base Tool: RAG-powered search for visa and policy information
- Vector Store: FAISS-based semantic search with OpenAI embeddings
{
"airline": "Turkish Airlines",
"alliance": "Star Alliance",
"from": "Dubai",
"to": "Tokyo",
"departure_date": "2024-08-15",
"return_date": "2024-08-30",
"layovers": ["Istanbul"],
"price_usd": 950,
"refundable": true
}
- Visa Requirements: Country-specific entry requirements and processing times
- Airline Policies: Refund, change, and baggage policies
User: "Find me a round-trip to Tokyo in August with Star Alliance airlines only. I want to avoid overnight layovers."
TravelWise AI:
βοΈ Found 2 flight(s):
βοΈ Flight 1:
β’ Airline: Turkish Airlines
β’ Alliance: Star Alliance
β’ Route: Dubai β Tokyo
β’ Departure: 2024-08-15
β’ Return: 2024-08-30
β’ Layovers: Istanbul
β’ Price: $950 USD
β’ Refundable: Yes
User: "Do I need a visa to visit Japan with a UAE passport?"
TravelWise AI: "UAE passport holders can enter Japan visa-free for up to 30 days for tourism. Your passport must be valid for at least 6 months from the date of entry. No visa application is required for short-term tourism visits."
User: "What's the cancellation policy for refundable tickets?"
TravelWise AI: "Refundable tickets can be canceled up to 48 hours before departure, subject to a 10% processing fee. Some premium airlines offer free cancellation up to 24 hours before departure."
- Role Definition: Clear travel assistant identity with specific capabilities
- Behavioral Guidelines: Professional, helpful, and travel-focused interactions
- Tool Usage Instructions: When and how to use available tools
- Response Formatting: Structured output with clear flight details and travel advice
- Conversation Memory: Maintains user preferences across interactions
- Query Understanding: Extracts multiple criteria from single natural language input
- Fallback Handling: Graceful degradation when searches return no results
The backend requires several environment variables to be configured. A template is provided in api/.env.example
:
PORT
: Backend server port (default: 8000)OPENAI_API_KEY
: Your OpenAI API keyMEMORY_SIZE
: Chat memory context sizeDEFAULT_MODEL
: LLM model to useDEFAULT_TEMPERATURE
: LLM temperature settingDEFAULT_SYSTEM_PROMPT
: Default system prompt for the chatbotRATE_LIMIT_*
: Rate limiting configurationsLANGSMITH_*
: LangSmith integration settings (optional)
Copy .env.example
to .env
and update the values as needed.
βββ api/ # Backend directory
β βββ app.py # Main FastAPI application
β βββ requirements.txt # Python dependencies
β βββ config/
β β βββ settings.py # Configuration and system prompts
β βββ module/
β β βββ agent.py # LangGraph agent implementation
β βββ tools/
β β βββ knowledgebase_tool.py # RAG-powered knowledge search
β β βββ flights.json # Mock flight listings dataset
β β βββ knowledge.txt # Travel knowledge base
β βββ faiss_index/ # Vector store for embeddings
β βββ Dockerfile # Backend container configuration
βββ docker-compose.yml # Docker services configuration
- Agent Orchestration: Sophisticated state management with tool routing
- Tool Integration: Seamless integration of multiple specialized tools
- Context Handling: Intelligent conversation memory with configurable limits
- Streaming Responses: Real-time response generation with timeout handling
- Multi-Format Processing: Handles both JSON flight data and text knowledge bases
- Vector Search Quality: FAISS-based semantic search with OpenAI embeddings
- Behavior Shaping: Comprehensive system prompts with clear role definition
- Natural Language Processing: Advanced query parsing and criteria extraction
- Response Formatting: Structured, user-friendly output formatting
- Fallback Handling: Graceful error handling and helpful suggestions
- Modular Design: Clean separation of concerns with reusable components
- Error Handling: Comprehensive logging and exception management
- Configuration Management: Environment-based configuration system
- Docker Support: Production-ready containerization