A production-ready AI chatbot powered by Google Vertex AI Gemini with conversation memory and tool-calling capabilities.
- π§ Persistent Memory: Conversation history stored in Firestore per session
- π οΈ Tool Calling: Calculator, web fetch, and email stub tools
- π Production Ready: Deploys to GCP Cloud Run
- π¬ Real-time UI: Clean, responsive chat interface
- π Secure: Input validation, whitelisting, safe execution
- Calculator: Safe mathematical expression evaluation
- Web Fetch: HTTP requests to whitelisted public APIs
- Email (Stub): Interface ready for Gmail API integration
- Python 3.11+
- GCP Project with Vertex AI API enabled
- Firestore database created
- GCP credentials configured locally
cd vertex-gemini-agent-chatbot
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtcp .env.example .env
# Edit .env with your GCP project detailsgcloud auth application-default login
gcloud config set project YOUR_PROJECT_IDpython app.pyVisit http://localhost:8080
gcloud run deploy vertex-gemini-chatbot \
--source . \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars GCP_PROJECT_ID=your-project-id,GCP_LOCATION=us-central1,GEMINI_MODEL=gemini-2.0-flash-exp,FIRESTORE_COLLECTION=chat_sessionsThe deployment will provide a URL like: https://vertex-gemini-chatbot-xxxxx-uc.a.run.app
# Send a chat message
curl -X POST http://localhost:8080/api/chat \
-H "Content-Type: application/json" \
-d '{"session_id": "test-session-1", "user_message": "What is 25 * 47?"}'
# Reset conversation
curl -X POST http://localhost:8080/api/reset \
-H "Content-Type: application/json" \
-d '{"session_id": "test-session-1"}'
# Test web fetch tool
curl -X POST http://localhost:8080/api/chat \
-H "Content-Type: application/json" \
-d '{"session_id": "test-session-2", "user_message": "Fetch the current Bitcoin price from https://api.coindesk.com/v1/bpi/currentprice.json"}'User β Flask App β Vertex AI Gemini β Tool Execution β Firestore
β β
HTML/CSS/JS Calculator/WebFetch/Email
- Calculator: Only evaluates safe mathematical expressions
- Web Fetch: Whitelisted domains only
- Email: Stub implementation with OAuth placeholder
- Input validation on all endpoints
- Request size limits enforced
To enable the email tool:
- Enable Gmail API in GCP Console
- Create OAuth 2.0 credentials
- Download credentials.json
- Run the OAuth flow locally
- Update
shared/tools.pywith credentials path - Uncomment email execution code
GCP_PROJECT_ID: Your GCP project IDGCP_LOCATION: Vertex AI location (e.g., us-central1)GEMINI_MODEL: Model name (default: gemini-2.0-flash-exp)FIRESTORE_COLLECTION: Collection name for chat history
MIT