A beginner-friendly AI Agent built with Python, LangChain, Google Gemini, and Streamlit.
The agent can understand user questions, use external tools when required, and provide a final response through a simple Streamlit chat interface.
- 🤖 Google Gemini AI model
- 🔎 Web search using DuckDuckGo
- 🌤️ Current weather information
- 🔢 Word counting tool
- 🛠️ Custom LangChain tools
- 💬 Streamlit chat interface
- 🔐 Environment variable support for API keys
- 🧠 Agent-based tool calling using LangChain
ai-agent/
│
├── app.py
├── agent.py
├── requirements.txt
├── .env
├── .gitignore
└── README.md
- Python
- LangChain
- Google Gemini
- Streamlit
- DuckDuckGo Search
- OpenWeatherMap API
This project uses:
MODEL_NAME = "gemini-3-flash-preview"The model is connected to LangChain using:
from langchain_google_genai import ChatGoogleGenerativeAIThe agent has three tools.
The agent can search the web when it needs external or current information.
search_tool = DuckDuckGoSearchRun()The custom weather tool uses the OpenWeatherMap API.
@tool
def get_weather(city: str) -> str:
...Example:
What's the current weather in Colombo?
A custom tool counts the number of words in a given text.
@tool
def word_counter(text: str) -> str:
...Example:
Count the words in this sentence:
AI agents can use tools.
The .env file in the project root:
GOOGLE_API_KEY=your_google_api_key
OPENWEATHERMAP_API_KEY=your_openweathermap_api_keyThe .gitignore is included:
.env
.venv/
__pycache__/
*.pyc
Clone the repository:
git clone https://github.com/your-username/your-repository.gitMove into the project directory:
cd AI AgentCreate a virtual environment:
python -m venv .venvActivate it.
Windows
.venv\Scripts\activateInstall the required packages:
pip install -r requirements.txtStart the Streamlit application:
streamlit run app.pyThen open the local URL shown in the terminal, usually:
http://localhost:8501
Try asking:
What is an AI agent?
What is the current weather in Kandy?
Search the web for the latest developments in AI agents.
Count the words in:
AI agents can use external tools.
The agent decides when a tool is required and uses the appropriate tool before generating the final response.
User
│
▼
Streamlit Interface
│
▼
LangChain AI Agent
│
▼
Gemini 3 Flash Preview
│
┌─────────┼─────────┐
▼ ▼ ▼
Web Search Weather Word Counter
│ │ │
└─────────┼─────────┘
▼
Final Response
│
▼
User
Through this project, I practiced:
- Building an AI agent with LangChain
- Using Google Gemini with LangChain
- Creating custom tools with
@tool - Tool calling and agent workflows
- Working with external APIs
- Web search integration
- Environment variable management
- Building a conversational UI with Streamlit
- Handling API errors and quota limits
- Separating AI logic from the user interface
The Gemini API has usage limits depending on the Google AI API project and billing tier.
If you receive:
429 RESOURCE_EXHAUSTED
check your Gemini API quota and usage.
Possible improvements include:
- 💾 Conversation memory
- 📄 PDF document analysis
- 🔍 RAG implementation
- 🔐 User authentication
- 🎨 Improved Streamlit UI
- ☁️ Deployment to Streamlit Community Cloud
This project was created as part of my learning journey in Artificial Intelligence, AI Agents, and Software Engineering.