An open API service indexing awesome lists of open source software.

https://github.com/anup4khandelwal/travel-planner-agent

Multi-agent conversational travel planner with TypeScript, LangChain, and Ollama
https://github.com/anup4khandelwal/travel-planner-agent

ai chatbot langchain travel typescript

Last synced: 3 months ago
JSON representation

Multi-agent conversational travel planner with TypeScript, LangChain, and Ollama

Awesome Lists containing this project

README

          

# Travel Planner Agent ๐ŸŒโœˆ๏ธ๐Ÿจ

A multi-agent conversational travel planner built with TypeScript, LangGraph, and Gemma3. This system provides a seamless, stateful chat interface for searching and booking flights and hotels through natural language queries.

## ๐Ÿ—๏ธ Architecture

```mermaid
flowchart TD
User[๐Ÿ‘ค User] --> ClassifierAgent[๐ŸŽฏ Intent Classifier]
ClassifierAgent --> DialogManager[๐Ÿง  Dialog Manager]
DialogManager -->|slots incomplete| FollowUpAgent[โ“ Follow-up Agent]
DialogManager -->|slots complete, intent Flight| FlightSearchAgent[โœˆ๏ธ Flight Search Agent]
DialogManager -->|slots complete, intent Hotel| HotelSearchAgent[๐Ÿจ Hotel Search Agent]
DialogManager -->|intent Other| FallbackAgent[๐Ÿค– Fallback Agent]
FlightSearchAgent --> ResponseStreamer[๐Ÿ“ก Response Streamer]
HotelSearchAgent --> ResponseStreamer
FallbackAgent --> ResponseStreamer
ResponseStreamer --> User

subgraph "Core Components"
SessionManager[๐Ÿ’พ Session Manager]
EntityExtractor[๐Ÿ” Entity Extractor]
end

DialogManager <--> SessionManager
DialogManager <--> EntityExtractor
```

## ๐Ÿš€ Features

- **๐ŸŽฏ Intent Classification**: Automatically detects Flight, Hotel, Both, or Other intents
- **๐Ÿ” Entity Extraction**: Extracts structured data (cities, dates, passengers) using Zod validation
- **๐Ÿ’ฌ Conversational Flow**: Maintains context and asks follow-up questions for missing information
- **๐Ÿ”„ Multi-Agent Orchestration**: Uses LangGraph pattern for agent coordination
- **๐Ÿ“ก Real-time Streaming**: Server-Sent Events (SSE) for responsive user experience
- **๐Ÿ’พ Session Management**: Stateful conversations with multi-user support
- **๐Ÿ›ก๏ธ Type Safety**: Full TypeScript implementation with Zod schema validation
- **๐Ÿงช Mock Search APIs**: Realistic flight and hotel search results for testing

## ๐Ÿ› ๏ธ Tech Stack

- **Language**: TypeScript (>=4.x)
- **Agent Framework**: LangGraph.js
- **LLM Model**: Gemma3:latest (via Ollama)
- **Web Framework**: Fastify
- **Schema Validation**: Zod
- **Runtime**: Node.js 18+
- **Testing**: Jest + Supertest

## ๐Ÿ“‹ Prerequisites

1. **Node.js 18+** installed
2. **Ollama** installed and running
3. **Gemma3 model** pulled in Ollama

### Setting up Ollama and Gemma3

```bash
# Install Ollama (macOS)
brew install ollama

# Start Ollama service
ollama serve

# Pull Gemma3 model (in another terminal)
ollama pull gemma3:latest
```

## ๐Ÿš€ Quick Start

### 1. Clone and Install Dependencies

```bash
cd travel-agent
npm install
```

### 2. Build the Project

```bash
npm run build
```

### 3. Start Development Server

```bash
npm run dev
```

### 4. Access the Application

- **Demo Interface**: http://localhost:3000
- **Health Check**: http://localhost:3000/health
- **API Endpoint**: POST http://localhost:3000/api/chat

## ๐Ÿ“ก API Reference

### Chat Endpoint

**POST** `/api/chat`

Send a message to the travel planner agent.

**Request Body:**
```json
{
"userId": "string",
"message": "string"
}
```

**Response:** Server-Sent Events stream

**Example:**
```bash
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"userId": "user123", "message": "Find flights from NYC to LA"}'
```

### Session Management

**GET** `/api/session/:userId` - Get session information
**DELETE** `/api/session/:userId` - Clear user session

### Health Check

**GET** `/health` - Server health and active sessions count

## ๐ŸŽฏ Usage Examples

### Flight Search
```
User: "I need a flight from New York to Los Angeles"
Agent: "When would you like to depart?"
User: "December 25th"
Agent: "How many passengers will be traveling?"
User: "2 passengers"
Agent: [Returns flight search results]
```

### Hotel Search
```
User: "Book me a hotel in Paris"
Agent: "When would you like to check in?"
User: "January 15th for 3 nights"
Agent: "How many guests will be staying?"
User: "2 guests"
Agent: [Returns hotel search results]
```

### Combined Trip Planning
```
User: "Plan a trip to Tokyo with flights and hotel"
Agent: "I can help you plan a complete trip! Where would you like to fly from?"
User: "San Francisco, departing March 10th, returning March 17th, for 2 people"
Agent: [Returns both flight and hotel results]
```

## ๐Ÿงช Testing

### Run All Tests
```bash
npm test
```

### Run Tests in Watch Mode
```bash
npm run test:watch
```

### Test Coverage
The test suite covers:
- Intent classification accuracy
- Entity extraction validation
- Session state management
- API endpoint functionality
- Error handling scenarios

## ๐Ÿ—๏ธ Project Structure

```
src/
โ”œโ”€โ”€ agents/ # AI Agents
โ”‚ โ”œโ”€โ”€ intent-classifier.ts
โ”‚ โ”œโ”€โ”€ entity-extractor.ts
โ”‚ โ”œโ”€โ”€ search-agents.ts
โ”‚ โ””โ”€โ”€ fallback-agent.ts
โ”œโ”€โ”€ core/ # Core Components
โ”‚ โ”œโ”€โ”€ dialog-manager.ts
โ”‚ โ””โ”€โ”€ session-manager.ts
โ”œโ”€โ”€ types/ # Type Definitions
โ”‚ โ””โ”€โ”€ schemas.ts
โ”œโ”€โ”€ __tests__/ # Test Files
โ”‚ โ”œโ”€โ”€ dialog-manager.test.ts
โ”‚ โ””โ”€โ”€ server.test.ts
โ”œโ”€โ”€ server.ts # Fastify Server
โ””โ”€โ”€ index.ts # Application Entry Point

public/
โ””โ”€โ”€ index.html # Demo Frontend

```

## ๐Ÿ”ง Configuration

### Environment Variables

```bash
# Server Configuration
PORT=3000 # Server port (default: 3000)
NODE_ENV=development # Environment mode

# LLM Configuration (choose one)
LLM_PROVIDER=ollama # Use 'ollama' for local or 'openai' for cloud
LLM_MODEL=gemma2:2b # Model name

# Ollama Configuration (if using LLM_PROVIDER=ollama)
OLLAMA_BASE_URL=http://localhost:11434

# OpenAI Configuration (if using LLM_PROVIDER=openai)
OPENAI_API_KEY=sk-your-key-here
```

### LLM Configuration

The system supports two LLM providers:

**Local Ollama (Development)**:
- Install and run Ollama locally
- Pull the model: `ollama pull gemma2:2b`
- Set `LLM_PROVIDER=ollama`

**OpenAI (Production/Cloud)**:
- Get API key from [platform.openai.com](https://platform.openai.com)
- Set `LLM_PROVIDER=openai` and `OPENAI_API_KEY=your-key`
- Recommended for cloud deployments

## ๐Ÿš€ Deployment

This application can be deployed in several ways. Choose the option that best fits your needs.

### Local Production Build
```bash
# Build the TypeScript code
npm run build

# Start the production server
npm start

# Required environment variables:
# PORT=3001 (optional, defaults to 3000)
# OLLAMA_BASE_URL=http://localhost:11434 (required for LLM functionality)
```

### Docker Deployment

The project includes a complete Docker setup for easy deployment.

#### Option 1: Using Docker Compose (Recommended)

```bash
# Start both the application and Ollama
docker-compose up -d

# Pull the Gemma3 model in Ollama
docker-compose exec ollama ollama pull gemma3:latest

# View logs
docker-compose logs -f

# Stop the services
docker-compose down
```

#### Option 2: Using Docker Directly

```bash
# Build the Docker image
docker build -t travel-planner-agent .

# Run the container
docker run -p 3001:3001 -e OLLAMA_BASE_URL=http://host.docker.internal:11434 travel-planner-agent
```

### Cloud Deployment Options

> ๐Ÿ“– **Quick Start**: See [QUICK_DEPLOY.md](./QUICK_DEPLOY.md) for step-by-step deployment instructions

#### Railway (Recommended)

1. Go to [railway.app](https://railway.app) and connect your GitHub repo
2. Set environment variables:
```
NODE_ENV=production
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-your-key-here
LLM_MODEL=gpt-3.5-turbo
```
3. Deploy automatically from GitHub

#### Vercel

1. Install Vercel CLI: `npm install -g vercel`
2. Deploy: `vercel --prod`
3. Set environment variables via Vercel dashboard

#### Render (Free Tier Available)

1. Create Web Service at [render.com](https://render.com)
2. Connect GitHub repository
3. Build command: `npm install && npm run build`
4. Start command: `npm start`
5. Add environment variables in Render dashboard
5. Add environment variables:
- `PORT=3001`
- `OLLAMA_BASE_URL=`

#### AWS Elastic Beanstalk Deployment

1. Create a `.ebextensions` folder with configuration files
2. Use the AWS Elastic Beanstalk CLI to deploy:
```bash
eb init
eb create travel-planner-env
eb deploy
```

### Important Deployment Notes

1. **Ollama Requirement**: This application requires access to an Ollama instance with the `gemma3:latest` model
2. **Environment Variables**: Make sure to set `OLLAMA_BASE_URL` to point to your Ollama instance
3. **Resource Requirements**: Ensure your deployment environment has sufficient resources for running LLM inference

## ๐Ÿ” Monitoring

### Health Check
Monitor application health at `/health` endpoint:

```json
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"activeSessions": 42
}
```

### Performance Metrics
- **Intent Classification**: ~200ms median response time
- **Concurrent Sessions**: Supports 1000+ active sessions
- **Memory Usage**: Optimized for production workloads

## ๐Ÿ›ก๏ธ Security

- **Input Validation**: All inputs validated using Zod schemas
- **CORS Protection**: Configured for allowed origins
- **Session Isolation**: User sessions are completely isolated
- **No Data Persistence**: Sessions stored in memory (Redis recommended for production)

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Built following the Travel Planner Agent PRD specifications
- Powered by LangGraph.js for multi-agent orchestration
- Uses Gemma3 for natural language understanding
- Inspired by modern conversational AI patterns

---

**๐Ÿš€ Ready to plan your next adventure? Start the server and begin chatting!**