A collection of intelligent search agents that connect various search engines with Large Language Models (LLMs) using LangChain. These agents can search the web, process results, and provide accurate, context-aware answers to your questions.
- 9 Complete Tutorials: From basics to advanced topics
- Multiple Search Providers: Google Custom Search, DuckDuckGo, Wikipedia
- Multi-Tool Agents: Combine search, calculator, and more
- Conversation Memory: Build context-aware chatbots
- RAG (Retrieval-Augmented Generation): Query your documents
- Data Analysis: Analyze CSV and SQL databases with natural language
- Custom Tools: Build your own agent capabilities
- Streaming Responses: Real-time token-by-token output
- LLM Integration: Support for OpenAI GPT, Llama, Claude, and other models
- Environment-based Configuration: Secure API key management
- Production Ready: Best practices, error handling, type hints
All notebooks are available in the notebooks/ directory and can be run in Google Colab:
| Agent Type | API Keys Needed | Best For | Complexity |
|---|---|---|---|
| DuckDuckGo Search | LLM only | Quick start, learning | Low |
| Google Search | LLM + Google | Production, quality results | Low |
| Multi-Tool | LLM only | Versatile Q&A | Medium |
| Conversational | LLM only | Chatbots, follow-ups | Medium |
| RAG Document | LLM only | Document analysis | High |
| Custom Tool | LLM only | Extensibility | Medium |
| CSV Analysis | LLM only | Data analysis | Medium |
| SQL Database | LLM only | Business intelligence | High |
| Streaming | LLM only | Better UX | Medium |
- Installation
- Quick Start
- Configuration
- Usage Examples
- API Key Setup
- Notebooks & Examples
- Architecture
- Contributing
- License
- Python 3.8 or higher
- pip package manager
- Clone the repository:
git clone https://github.com/nluninja/langchain_agents.git
cd langchain_agents- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtClick the badge in the notebook to open directly in Colab:
- Copy the example environment file:
cp .env.example .env- Edit
.envand add your API keys:
# Required: Choose your LLM provider
OPENAI_API_KEY=sk-...
# OR
GROQ_API_KEY=gsk_...
# OR
ANTHROPIC_API_KEY=sk-ant-...
# Required: For Google Custom Search
GOOGLE_API_KEY=AIza...
GOOGLE_CSE_ID=0123456789...Important: Never commit your .env file to version control!
- Open
LangChain_GoogleSearch_Llama33.ipynbin Jupyter or Google Colab - Add your API keys to the environment variables
- Run all cells
- Enter your question when prompted
from dotenv import load_dotenv
from langchain_agents import SearchAgent
# Load environment variables
load_dotenv()
# Create agent
agent = SearchAgent()
# Ask a question
response = agent.ask("What are the latest developments in AI?")
print(response)# Simple factual question
agent.ask("What is the capital of France?")
# Current events
agent.ask("What are today's top news stories?")
# Research question
agent.ask("How does photosynthesis work?")# Use specific search provider
agent = SearchAgent(search_provider="duckduckgo")
# Customize model parameters
agent = SearchAgent(
model="gpt-4",
temperature=0.7,
max_tokens=500
)
# Enable verbose mode for debugging
agent = SearchAgent(verbose=True)- Go to Google Cloud Console
- Create a new project or select existing one
- Enable "Custom Search API"
- Create credentials (API key)
- Set up a Custom Search Engine
- Copy your API key and Search Engine ID to
.env
Free tier: 100 queries per day
- Visit OpenAI Platform
- Create an account and add payment method
- Generate an API key from the API keys page
- Copy to
.envasOPENAI_API_KEY
Pricing: Pay per token used
- Visit Groq Console
- Sign up for free account
- Generate an API key
- Copy to
.envasGROQ_API_KEY
Free tier: Generous rate limits for Llama models
DuckDuckGo search requires no API key! Just install:
pip install duckduckgo-searchThe examples/ directory contains standalone Python scripts for common use cases:
Simple search agent using DuckDuckGo (no API keys required for search):
python examples/basic_search.pyAgent with multiple tools (search, calculator, Wikipedia):
python examples/multi_tool_demo.pyInteractive chatbot with conversation memory:
python examples/conversational_bot.pyAll examples use .env file for API keys - see Configuration for setup.
βββββββββββββββ
β User β
β Question β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β LangChain β
β Agent β
ββββββββ¬βββββββ
β
βββββββββββββββ
βΌ βΌ
βββββββββββββββ ββββββββββββ
βSearch Tool β β LLM β
β (Google/ β β(GPT/ β
β DuckDuckGo) β βLlama/ β
ββββββββ¬βββββββ βClaude) β
β ββββββ¬ββββββ
βΌ β
βββββββββββββββ β
β Search β β
β Results β β
ββββββββ¬βββββββ β
β β
ββββββββ¬βββββββ
βΌ
βββββββββββββββ
β Answer β
βββββββββββββββ
- LangChain Agent: Orchestrates the workflow and decides when to search
- Search Tool: Queries search engines and retrieves relevant information
- LLM: Processes search results and generates natural language answers
- Prompt Template: Structures the context and question for the LLM
pip install -r requirements-dev.txt
pytest tests/black .
isort .
flake8 .pre-commit install
pre-commit run --all-filesContributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain - Framework for building LLM applications
- OpenAI - GPT models
- Groq - Fast inference for Llama models
- Google Custom Search - Web search API
Project Link: https://github.com/nluninja/langchain_agents
This project is for educational purposes. Be mindful of API rate limits and costs. Always follow the terms of service for the APIs you use.
Happy searching! π