This project demonstrates how to create basic AI agent using Google's Agent Development Kit (ADK) that can help users find direct flights between cities. The agent uses Google Search to find flight information and provides intelligent responses to user queries.
- Direct Flight Search: Find direct flights between any two cities
- Flight Information: Get details about airlines, schedules, and pricing
- Alternative Suggestions: Receive suggestions for connecting flights when direct flights aren't available
- Smart Query Processing: Natural language understanding for flight requests
Before you begin, make sure you have:
- Python 3.8+ installed on your system
- Google AI Studio API Key - Get one from Google AI Studio
- Basic knowledge of Python and command line operations
git clone https://github.com/dev-muhammad/flight_search_agent_adk.git
cd flight_search_agent_adk
# Create virtual environment
python -m venv flight_agent_env
# Activate virtual environment
# On macOS/Linux:
source flight_agent_env/bin/activate
# On Windows:
flight_agent_env\Scripts\activate
pip install -r requirements.txt
Copy the example environment file and configure your API key:
cp .env.example .env
Get your Google AI API key from Google AI Studio and update the .env
file:
GOOGLE_API_KEY=your_actual_api_key_here
-
Start the Agent with builtin WebUI:
adk web
-
Interact with the Agent: Once running, open http://127.0.0.1:8000 in your browser. You can ask questions like:
- "Find direct flights from New York to London"
- "Are there any direct flights between Tokyo and Paris?"
- "Show me flight options from Los Angeles to Dubai"
- "What airlines fly direct from Mumbai to Singapore?"
Important: The built-in web UI is designed for development and testing purposes only.
For production deployment, you have several options:
- Integration with existing applications: Embed the agent into your web app or mobile app
- API endpoints: Deploy as a REST API service
- Chat platforms: Connect to Slack, Discord, or other messaging platforms
- Cloud deployment: Deploy on Google Cloud, AWS, or Azure
For detailed production deployment guides and examples, visit the ADK Deployment Documentation.
flight_search_agent/
├── README.md # This file
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
├── .env.example # Example of .env file
├── .gitignore # Git ignore file
└── flight_search_agent/ # Main agent directory
├── __init__.py # Python package file
└── agent.py # Main agent implementation
The flight search agent is built using Google's ADK and consists of:
- Agent Definition: Defined in
flight_search_agent/agent.py
- Google Search Tool: Built-in ADK tool for web searches
- Instructions: Detailed system prompt that guides the agent's behavior
- Model: Uses Google's Gemini 2.0 Flash model for natural language processing
from google.adk.agents import Agent
from google.adk.tools import google_search
root_agent = Agent(
name="flight_search_agent",
model="gemini-2.0-flash",
description="Flight search agent for finding direct flights between cities",
instruction="...", # Detailed instructions for flight search behavior
tools=[google_search],
)
You can customize the agent's behavior by editing the instruction
field in agent.py
. For example:
- Add specific airline preferences
- Include price comparison features
- Add travel date flexibility options
- Include hotel and car rental suggestions
You can extend the agent with additional tools:
from google.adk.tools import google_search
def get_weather(city: str, unit: str):
"""
Retrieves the weather for a city in the specified unit.
Args:
city (str): The city name.
unit (str): The temperature unit, either 'Celsius' or 'Fahrenheit'.
"""
# ... function logic ...
return {"status": "success", "report": f"Weather for {city} is sunny."}
root_agent = Agent(
# ... other parameters
tools=[google_search, get_weather],
)
-
API Key Not Working:
- Verify your API key is correct in the
.env
file - Ensure the key has proper permissions
- Check if you've exceeded API rate limits
- Verify your API key is correct in the
-
Import Errors:
- Make sure you've installed all requirements:
pip install -r requirements.txt
- Verify you're using the correct Python version (3.8+)
- Make sure you've installed all requirements:
-
Agent Not Responding:
- Check your internet connection
- Verify the Google ADK service is running
- Look for error messages in the console
If you encounter issues:
- Check the Google ADK documentation
- Review the console output for error messages
- Ensure all dependencies are properly installed
Once you have the basic agent working, consider these enhancements:
- Add More Specific Search Queries: Improve search precision for better results
- Price Comparison: Integrate with flight booking APIs for real-time pricing
- Date Flexibility: Add features to suggest alternative travel dates
- Multi-City Search: Extend to handle complex itineraries
- User Preferences: Store user preferences for personalized results
Feel free to contribute improvements to this project:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This project uses Google ADK, which has its own licensing terms. Please review Google ADK's license terms for commercial usage.
- Google ADK Documentation
- Google AI Studio
- Article:
Note: This project was created as a demonstration for the article "How to Create AI Agents: A Practical Guide for New Developers"