A simple LangChain agent that uses web search tools to answer questions about any city around the world. Configured to work with FREE API keys!
- 🔍 Web search capabilities using DuckDuckGo (completely free, no API key needed)
- 🤖 Supports OpenAI or Google Gemini (both have free tiers)
- 📊 Optional LangSmith integration for monitoring and tracing
- 🌍 Works for any city - San Francisco, Seattle, New York, London, Tokyo, and more!
- 💬 Interactive command-line interface
pip install -r requirements.txtYou need at least ONE of the following API keys (both are free!):
OpenAI offers $5 in free credits for new users (valid for 3 months)
- Go to https://platform.openai.com/
- Sign up for a free account (or log in if you already have one)
- Click on your profile icon (top right) → "View API Keys"
- Click "Create new secret key"
- Copy the key immediately (you won't see it again!)
- Add it to your
.envfile (see step 3 below)
Note: The free $5 credit is enough for thousands of queries with gpt-4o-mini model.
Google Gemini has a generous free tier
- Go to https://aistudio.google.com/app/apikey
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key
- Add it to your
.envfile (see step 3 below)
Note: You can use both API keys if you want - the agent will prefer OpenAI but fallback to Gemini.
Create a .env file in the project root:
# Option 1: OpenAI (Recommended - $5 free credits for new users)
OPENAI_API_KEY=your_openai_api_key_here
# Option 2: Google Gemini (Alternative free option)
GOOGLE_API_KEY=your_google_api_key_here
# Optional: LangSmith tracing (not required, but useful for debugging)
LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=gainesville-agentMinimum setup: You only need ONE of OPENAI_API_KEY or GOOGLE_API_KEY. The rest is optional.
python agent.pyThen ask questions about Gainesville, Florida:
🤔 Your question: What is the population of Gainesville?
🤔 Your question: What are some popular restaurants in Gainesville?
🤔 Your question: Tell me about the University of Florida
🤔 Your question: What's the weather like in Gainesville?
Type quit or exit to stop the agent.
| Service | Free Tier | How to Get |
|---|---|---|
| OpenAI | $5 free credits (3 months) | platform.openai.com → Sign up → API Keys |
| Google Gemini | Generous free tier | aistudio.google.com → Create API Key |
| DuckDuckGo Search | Completely free | No API key needed! |
| LangSmith | Free tier available | Optional - only for tracing/debugging |
You can ask about any city! Here are some examples:
- "What is the population of San Francisco?"
- "Tell me about Seattle"
- "What are the best restaurants in New York?"
- "What's the weather like in London?"
- "What is the cost of living in Tokyo?"
- "What are the top tourist attractions in Paris?"
- "What events are happening in Miami this weekend?"
LangSmith is completely optional and only used for monitoring/debugging. To enable:
- Sign up at https://smith.langchain.com/
- Get your API key from the settings
- Add
LANGCHAIN_API_KEYto your.envfile
You can skip this entirely if you don't need tracing.
gainesville-agent/
├── agent.py # Main agent implementation
├── requirements.txt # Python dependencies
├── .env # Your API keys (create this file)
└── README.md # This file
- The agent uses LangChain's ReAct agent framework
- Web search is powered by DuckDuckGo Search (free, no API key)
- LLM is powered by OpenAI (free $5 credits) or Google Gemini (free tier)
- Optional LangSmith tracking for agent interactions
- The agent automatically identifies the city from your question and searches for relevant information
- Python 3.8+
- At least ONE of:
- OpenAI API key (free $5 credits for new users)
- Google Gemini API key (free tier)
- LangSmith API key (optional, only for tracing)
- Make sure you have at least one API key in your
.envfile - Check that the
.envfile is in the same directory asagent.py - Verify your API key is correct (no extra spaces)
- Check your account has remaining credits at platform.openai.com/usage
- Free credits expire after 3 months
- Make sure you're using
gpt-4o-mini(the cheapest model) to maximize free credits
- Verify your API key at aistudio.google.com
- Check if you've exceeded the free tier limits
- DuckDuckGo Search: Free forever, no limits
- OpenAI: $5 free credits for new users (lasts ~3 months, thousands of queries)
- Google Gemini: Free tier with generous limits
- LangSmith: Free tier available (optional)
All services used here have free tiers that are sufficient for personal use and testing!