This is an intelligent hotel booking assistant built with Next.js, Flutter, and LangGraph. The application uses AI to search over platform and find the cheapest options for your travel needs.
- Smart Hotel Search: Natural language hotel search queries (e.g., "Find a cheap hotel in Paris for next weekend")
- LangGraph Workflow: Advanced AI workflow with StateGraph, conditional routing, and state management
- Real-time Streaming: Stream search results and analysis in real-time
- Cheapest Option Recommendation: Automatically finds and recommends the most affordable option
- Quick Search Buttons: Pre-configured search options for popular destinations
- Follow-up Questions: Ask clarifying questions or modify search parameters
- Modern UI: Beautiful, responsive interface with syntax highlighting and markdown support
The application uses LangGraph's StateGraph for sophisticated AI workflow orchestration:
- Query Parsing: AI intelligently parses natural language queries and maintains conversation context
- Conditional Routing: LangGraph's conditional edges route workflow based on state conditions
- Price Analysis: Advanced comparison algorithm with detailed LLM-powered recommendations
- State Management: LangGraph's annotation-based state with automatic merging and validation
graph TD
A[User Query] --> B[Parse Query Node]
B --> C{Valid Query?}
C -->|No| D[Request Clarification]
C -->|Yes| E[Search Hotels Node]
E --> F{Results Found?}
F -->|No| G[Error Handling]
F -->|Yes| H[Analyze & Select Node]
H --> I[Return Recommendations]
D --> A
G --> I
This project uses:
- pnpm as the package manager
- Node.js version specified in
.tool-versions - Google Gemini API for AI processing
- Flutter for mobile app development
First, ensure you have the correct Node.js version installed:
# If using asdf
asdf install
# Or check .tool-versions for the required versionsInstall dependencies:
pnpm installFirst, ensure you have the correct Flutter version installed:
# Install Flutter (if not already installed)
# See: https://docs.flutter.dev/get-started/install
flutter --versionInstall dependencies:
flutter pub getCreate a .env.local file in the root directory and add your API keys:
# Google Gemini API Key (required)
# Get your API key from: https://ai.google.dev/
GEMINI_API_KEY=your_gemini_api_key_hereCreate a .env or similar environment file in your Flutter project:
GEMINI_API_KEY=your_gemini_api_key_here
### 3. Run the Development Server
#### 3.1. Web
```bash
pnpm dev
Open http://localhost:3000/llm with your browser to access the hotel search interface.
flutter runThis will launch the mobile app on your connected device or emulator.
Try these natural language queries:
- "Find a cheap hotel in New York for December 25-27 for 2 guests"
- "Budget hotel in London for 1 night"
- "Family hotel in Orlando for 4 guests, 3 nights"
- "Hotel in Tokyo for 2 people, next weekend"
The system maintains conversation context, so you can ask:
- "What about for 3 nights instead?"
- "Show me options under $150 per night"
- "Any hotels with pools?"
- "Change dates to next month"
The application uses LangGraph's powerful StateGraph for workflow orchestration:
- Annotation-based State: Type-safe state definition using LangGraph Annotations
- Automatic State Merging: LangGraph handles state updates and merging automatically
- Conversation History: Maintains full context across multiple interactions
- Error Propagation: Graceful handling of errors through state channels
- Pure Function Nodes: Each node is a pure function that returns partial state updates
- Conditional Routing: LangGraph's conditional edges route based on state conditions
- Graph Compilation: Optimized execution plan with built-in error handling
- START/END Nodes: Proper workflow entry and exit points
// Each node is a pure function in LangGraph
async function parseQuery(state: typeof GraphState.State) {
// Process the state and return partial updates
return {
query: extractedQuery,
analysis: "Parsing complete"
};
}const GraphState = Annotation.Root({
query: Annotation<HotelSearchQuery>({
reducer: (current, update) => update ?? current,
default: () => ({} as HotelSearchQuery),
}),
// ... other state fields
});- Frontend: Next.js 15, React 19, TypeScript
- AI/LLM: Google Gemini 2.0 Flash, LangChain Core
- Workflow Engine: LangGraph StateGraph with Annotation-based state
- UI Components: LLM-powered UI with React Markdown and syntax highlighting
- Code Highlighting: Shiki for syntax highlighting
- Markdown: React Markdown with GFM support
- Streaming: Server-Sent Events for real-time updates
The mobile client is a Flutter app located in the llm-flutter directory. It provides a modern chat interface for hotel price search, powered by the same AI backend as the web app.
- Conversational hotel search with context-aware follow-ups
- Real-time streaming of results using Server-Sent Events (SSE)
- Modern chat UI (using
flutter_chat_ui) - Markdown and code block rendering in chat
- Quick search suggestions
-
Install Flutter
Follow the Flutter install guide and ensure you have Flutter 3.5.3+:flutter --version
-
Install dependencies
flutter pub get
-
Configure API Endpoint
The app communicates with the backend at:https://initiative-hotel-agent.vercel.app/api/chat-llmIf you deploy your own backend, update the
apiUrlinlib/chat_api_service.dart. -
Run the app
flutter run
lib/main.dart– App entry point, sets up theming and home screenlib/chat_screen.dart– Main chat UI and logiclib/chat_api_service.dart– Handles communication with the backend API (SSE streaming)lib/chat_view_model.dart– Manages chat state and message flow
- Uses HTTP POST and SSE to stream AI responses from the backend.
- No API key is required on the mobile client; the backend handles Gemini API access.
Key packages:
flutter_chat_ui– Chat interfaceflutter_client_sse– Server-Sent Events for real-time streaminghttp– HTTP requestsflutter_markdown– Markdown rendering
See llm-flutter/pubspec.yaml for the full list.
- To change the backend endpoint, edit
apiUrlinlib/chat_api_service.dart. - To add features or UI tweaks, modify
lib/chat_screen.dartandlib/chat_view_model.dart.
The LangGraph StateGraph can be extended by:
- Adding New Nodes: Create new processing steps
async function newProcessingNode(state: typeof GraphState.State) {
// Custom logic
return {
customField: processedData,
analysis: "Custom processing complete"
};
}
// Add to workflow
.addNode("newProcessing", newProcessingNode)- Adding Conditional Edges: Implement smart routing
function shouldProcessCustom(state: typeof GraphState.State): string {
if (state.customCondition) {
return "customProcessing";
}
return "defaultPath";
}
// Add conditional routing
.addConditionalEdges("parseQuery", shouldProcessCustom, {
customProcessing: "customProcessing",
defaultPath: "searchHotels",
})- Extending State: Add new state fields
const ExtendedGraphState = Annotation.Root({
...GraphState.spec, // Inherit existing state
customField: Annotation<CustomType>({
reducer: (current, update) => update ?? current,
default: () => defaultValue,
}),
});- Components: All UI components are modular and can be customized
- Styling: CSS modules allow easy theming and customization
- Quick Actions: Modify
src/app/llm/constants.tsfor different quick search options
The self-managed LangGraph architecture opens numerous expansion possibilities:
- API Partnerships: Direct integration with hotel booking APIs for real-time/cached pricing
- Commission Systems: Revenue optimization through booking partnerships
- Advertising Integration: Sponsored hotel recommendations and placements
- Multi-Agent Systems: Specialized agents for different aspects (pricing, amenities, reviews)
- Advanced LLM Integration: Support for multiple AI providers and model switching
- Predictive Analytics: Price trend analysis and optimal booking time recommendations
- Vector Database Integration: Enhanced search capabilities with semantic similarity
- Caching Layers: Redis integration for improved response times
- Analytics Dashboard: Comprehensive search and booking analytics
- Personalization Engine: Machine learning-powered user preference learning
GEMINI_API_KEY=your_production_gemini_api_key- LangGraph Optimization: Compiled StateGraph for efficient execution
- Streaming: Uses Server-Sent Events for real-time updates
- Error Recovery: LangGraph's built-in error handling and state management
- State Validation: Automatic state merging and validation
- Caching: Browser caching for static assets
Advanced workflow orchestration with automatic state management, conditional routing, and built-in error handling.
LangGraph's state management maintains context across queries, allowing for natural follow-up questions.
Advanced AI parsing with LangGraph's conditional edges that handle ambiguous queries and request clarification.
LangGraph's conditional edges adapt the workflow based on query complexity and results.
- LangGraph Documentation
- LangChain JS Documentation
- LangGraph JS Documentation
- Google Gemini API
- Next.js Documentation
- React 19 Features
- Flutter Documentation
- Follow TypeScript best practices
- Use LangGraph patterns for workflow modifications
- Maintain annotation-based state definitions
- Add proper error handling in nodes
- Include tests for new features
- Update documentation