Skip to content

ehsanahmadkhan525/tensorark-langgraph-fastapi-starter-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TravelWise AI - Conversational Travel Assistant

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.

🌍 Features

Core Functionality

  • 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

Technical Capabilities

  • 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

Local Setup

Backend (Python FastAPI)

  1. Create and activate a virtual environment:
python3 -m venv env
source env/bin/activate  # On Windows: .\env\Scripts\activate
  1. Set up environment variables:
cd api
cp .env.example .env
# Edit .env file and add your API keys and configurations
  1. Install dependencies:
pip install -r requirements.txt
  1. 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.

Docker Setup

The application is containerized using Docker and orchestrated with Docker Compose.

Prerequisites

  • Docker
  • Docker Compose

Running with Docker

  1. Set up environment variables:
cd api
cp .env.example .env
# Edit .env file with your API keys and configurations
cd ..
  1. Build and start the containers:
docker compose up --build
  1. Access the application:

Port Configuration

  • Backend:
    • Local development: Port 8000
    • Docker: External port 8000, internal port 8000

πŸ—οΈ System Architecture

Agent-Based Design

  • 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

Data Processing Pipeline

  1. Query Parsing: Natural language understanding and intent extraction
  2. Criteria Normalization: Convert conversational input to structured search parameters
  3. Multi-Source Search: Vector search across flight data and knowledge base
  4. Result Synthesis: Formatting of results
  5. Context Management: Maintain conversation state and preferences

Tool Architecture

  • Knowledge Base Tool: RAG-powered search for visa and policy information
  • Vector Store: FAISS-based semantic search with OpenAI embeddings

πŸ“Š Data Structure

Flight Data Format (JSON)

{
  "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
}

Knowledge Base Content

  • Visa Requirements: Country-specific entry requirements and processing times
  • Airline Policies: Refund, change, and baggage policies

πŸ’¬ Sample Interactions

Natural Language Flight Search

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

Visa Information Query

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."

Policy Questions

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."

🎯 Prompt Engineering Strategy

System Prompt Design

  • 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

Context Management

  • 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

Environment Variables

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 key
  • MEMORY_SIZE: Chat memory context size
  • DEFAULT_MODEL: LLM model to use
  • DEFAULT_TEMPERATURE: LLM temperature setting
  • DEFAULT_SYSTEM_PROMPT: Default system prompt for the chatbot
  • RATE_LIMIT_*: Rate limiting configurations
  • LANGSMITH_*: LangSmith integration settings (optional)

Copy .env.example to .env and update the values as needed.

πŸ“ Project Structure

β”œβ”€β”€ 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

πŸ† Technical Highlights

LangChain/LangGraph Implementation

  • 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

RAG & Retrieval Excellence

  • Multi-Format Processing: Handles both JSON flight data and text knowledge bases
  • Vector Search Quality: FAISS-based semantic search with OpenAI embeddings

Prompt Engineering Mastery

  • 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

Code Quality & Architecture

  • 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

About

Easy to use LangGraph FastAPI Template with ReAct Agent with custom tools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published