Flight Agent
Search engine and graph for flights and accomodation
Overview
Flight Agent is a search engine that aggregates and analyzes flight data to discover all viable routes within a specified budget constraint. The system integrates Parallel API to scrape flight information from booking platforms like Expedia and Google Flights, while also retrieving popular tourist attractions at each potential destination.
All route possibilities are rendered through a MapLibre visualization, enabling users to explore geographic relationships between destinations and evaluate points of interest in a unified interface.
Technical Architecture
The application was built with a multi-stage data processing pipeline:
Data Aggregation Layer
User queries trigger Parallel API requests which scrape flight data from multiple sources, returning structured JSON responses containing route information, pricing, and availability. This raw data is then processed through Claude's API, which serves as the orchestration layer, filtering results against the specified budget and identifying valid route combinations.
API and Visualization Layer
The processed results are exposed via API endpoints that feed into the frontend in which MapLibre consumes this data to render flight routes, destination markers, and tourist attractions. The interface enables users to navigate between different routes, inspect flight information, and explore points of interest within a single workflow.
Caching
To optimize response times for frequently requested routes, the system implements a Redis caching layer. Query results are cached, allowing subsequent identical searches to bypass the full scraping and processing pipeline, which reduces latency for common pairs and budget ranges, as well as API credits.
Implementation Example
Here's an example of querying Parallel API for flight data and the JSON response it returns:
// Query Parallel API for flight data
const response = await fetch('https://api.parallelapis.com/flights', {
method: 'POST',
headers: { 'Authorization': 'Bearer API_KEY' },
body: JSON.stringify({
origin: 'JFK',
budget: 500,
date: '2024-03-15'
})
});
const data = await response.json();
// Example response structure:
{
"flights": [
{
"destination": "BOS",
"price": 189,
"airline": "JetBlue",
"duration": "1h 15m",
"departure": "08:30",
"arrival": "09:45"
},
{
"destination": "ORD",
"price": 245,
"airline": "United",
"duration": "2h 45m",
"departure": "10:00",
"arrival": "11:45"
},
{
"destination": "LAX",
"price": 389,
"airline": "Delta",
"duration": "5h 30m",
"departure": "07:00",
"arrival": "10:30"
}
],
"total_results": 47
}The flight data is then processed through Claude to filter routes and aggregate attraction data:
// Process through Claude agent
const claudeResponse = await anthropic.messages.create({
model: 'claude-3-5-sonnet-20241022',
messages: [{
role: 'user',
content: `Analyze these flights: ${JSON.stringify(data.flights)}
Find tourist attractions for each destination.
Return structured JSON with routes and attractions.`
}]
});
const processedData = JSON.parse(claudeResponse.content[0].text);