A conversational AI assistant built using Google's Gemini API with function-calling capabilities. Unlike a standard chatbot, PolyAgent autonomously decides which tool to use based on the user's question — performing calculations, fetching live weather, searching the web, converting currencies, and retrieving Wikipedia summaries — all through natural conversation.
- Autonomous Tool Selection: The AI model analyzes each user query and automatically determines which tool (if any) is needed to answer accurately, rather than relying on hardcoded logic.
- Real-Time Data Tools:
- Live weather lookup via OpenWeatherMap API
- Web search via DuckDuckGo for current events and factual queries
- Currency conversion using live exchange rates
- Wikipedia summaries for quick factual lookups
- Arithmetic calculations handled through a dedicated function
- Robust Error Handling: Gracefully handles API rate limits, server unavailability, and configuration issues with user-friendly messages instead of crashes, including automatic retry logic for transient failures.
- Conversational Memory: Maintains context across a full conversation session using Gemini's chat interface, allowing natural follow-up questions.
- Secure Configuration: API keys managed through environment variables, never hardcoded.
- Language: Python
- AI Model: Google Gemini (via
google-genaiSDK) - APIs: OpenWeatherMap, ExchangeRate-API, Wikipedia REST API, DuckDuckGo Search
- Libraries:
requests,python-dotenv,ddgs
- The user sends a natural-language message.
- Gemini evaluates the message against the available tool descriptions.
- If a tool is needed, Gemini selects the appropriate function and generates the correct parameters.
- The Python backend executes the real function (API call or computation) and returns the result.
- Gemini synthesizes the tool's output into a clear, conversational response.
- Clone this repository
- Create a virtual environment:
python -m venv venv - Activate it:
venv\Scripts\activate(Windows) orsource venv/bin/activate(Mac/Linux) - Install dependencies:
pip install -r requirements.txt - Create a
.envfile with your API keys: - Run:
python main.py
You: What's the weather in Hyderabad? Assistant: It's currently 26°C with overcast clouds in Hyderabad.
You: Convert 100 dollars to rupees Assistant: 100 USD = 8,742.50 INR
You: What is 1234 plus 9876? Assistant: 1234 + 9876 = 11,110
- Persistent conversation memory across sessions (saved to a local database)
- Web-based interface built with Streamlit
- Additional tools (news headlines, translation)
- Source-attribution labeling to distinguish AI-generated knowledge from live search resultsgit init