Skip to content

sidrad17/LangChainAgent

Repository files navigation

City Information Agent

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!

Features

  • 🔍 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

Setup

1. Install Dependencies

pip install -r requirements.txt

2. Get FREE API Keys

You need at least ONE of the following API keys (both are free!):

Option 1: OpenAI API Key (Recommended - Easiest to get)

OpenAI offers $5 in free credits for new users (valid for 3 months)

  1. Go to https://platform.openai.com/
  2. Sign up for a free account (or log in if you already have one)
  3. Click on your profile icon (top right) → "View API Keys"
  4. Click "Create new secret key"
  5. Copy the key immediately (you won't see it again!)
  6. Add it to your .env file (see step 3 below)

Note: The free $5 credit is enough for thousands of queries with gpt-4o-mini model.

Option 2: Google Gemini API Key (Alternative Free Option)

Google Gemini has a generous free tier

  1. Go to https://aistudio.google.com/app/apikey
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy the generated key
  5. Add it to your .env file (see step 3 below)

Note: You can use both API keys if you want - the agent will prefer OpenAI but fallback to Gemini.

3. Configure Environment Variables

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-agent

Minimum setup: You only need ONE of OPENAI_API_KEY or GOOGLE_API_KEY. The rest is optional.

4. Run the Agent

python agent.py

Then 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.

Free API Key Summary

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

Example Questions

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 Tracing (Optional)

LangSmith is completely optional and only used for monitoring/debugging. To enable:

  1. Sign up at https://smith.langchain.com/
  2. Get your API key from the settings
  3. Add LANGCHAIN_API_KEY to your .env file

You can skip this entirely if you don't need tracing.

Project Structure

gainesville-agent/
├── agent.py           # Main agent implementation
├── requirements.txt   # Python dependencies
├── .env              # Your API keys (create this file)
└── README.md         # This file

How It Works

  1. The agent uses LangChain's ReAct agent framework
  2. Web search is powered by DuckDuckGo Search (free, no API key)
  3. LLM is powered by OpenAI (free $5 credits) or Google Gemini (free tier)
  4. Optional LangSmith tracking for agent interactions
  5. The agent automatically identifies the city from your question and searches for relevant information

Requirements

  • 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)

Troubleshooting

"No LLM configured" error

  • Make sure you have at least one API key in your .env file
  • Check that the .env file is in the same directory as agent.py
  • Verify your API key is correct (no extra spaces)

OpenAI API errors

  • 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

Google Gemini API errors

Cost Information

  • 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!

About

simple agent to respond to any questions about gainesville, florida

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages