This project is a Flask-based web application demonstrating an autonomous agent powered by Google's Gemini models. The agent is capable of performing various tasks through tool integration, including real-time web search, email management, and news aggregation.
- Interactive Chat Interface: Seamless conversation with the Gemini agent.
- Autonomous Capabilities:
- Web Search: Retrieves real-time information using Google Custom Search.
- Email Management: Reads unread emails and sends new emails via Gmail integration.
- News Aggregator: Fetches and summarizes the latest news from Google News RSS feeds.
- Chat Management: Create, load, and manage chat sessions with persistent history.
- Backend: Flask (Python)
- AI Model: Google Gemini (via
google-genaiSDK) - Search: Google Custom Search JSON API
- Email: SimpleGmail
- News Extraction:
feedparser,newspaper3k,googlenewsdecoder - Frontend: HTML/CSS (Jinja2 templates)
- Python 3.8+
- A Google Cloud Project with the following APIs enabled:
- Gemini API
- Custom Search API
- Gmail API
-
Clone the repository:
git clone <repository-url> cd Gemini-Autonomous-Agent-Demo
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Environment Variables: Create a
.envfile in the root directory (use.env.exampleas a reference) and add your API keys:GEMINI_API_KEY=your_gemini_api_key GEMINI_MAIN_MODEL=gemini-2.0-flash-exp GEMINI_QUICK_MODEL=gemini-2.0-flash-exp SEARCH_API_KEY=your_google_custom_search_api_key SEARCH_ENGINE_ID=your_search_engine_id PRIMARY_USER_MAIL=your_email@gmail.com
-
Gmail Credentials:
- Download your
client_secret.jsonfrom the Google Cloud Console (OAuth 2.0 Client IDs). - Place it in the
gmail_credentials/directory. - Run the initial setup script (if applicable) or ensure the app handles the initial OAuth flow to generate
gmail_token.json.
- Download your
-
Run the application:
python app.py
-
Access the interface: Open your browser and navigate to
http://127.0.0.1:7777.
app.py: Main entry point for the Flask application.routes.py: API route definitions.views.py: Logic for chat handling and interactions.utils.py: Implementation of tool functions (Search, Email, News).tool_declarations.py: Definitions of tools exposed to the Gemini model.templates/: HTML templates for the frontend.