An intelligent multi-agent system that routes queries to specialized agents for weather information and document-based question answering using LangGraph, LangChain, and OpenAI.
Deployed Link: [(https://langraph-weather-pdf-agent.streamlit.app/)]
This project implements an intelligent agentic system that uses LangGraph for orchestration and routing. The system automatically classifies user queries and routes them to specialized agents:
- 🌤️ Weather Agent: Retrieves real-time weather data using OpenWeather API
- 📄 Document RAG Agent: Answers questions from uploaded PDF documents using vector similarity search
- LangGraph: Agent orchestration and state management
- LangChain: RAG chains and document processing
- OpenAI GPT-4o-mini: Query classification and document QA
- Qdrant: Cloud vector database for document embeddings
- Streamlit: Interactive web interface
- LangSmith: Observability and tracing
- LLM-based classification using GPT-4o-mini
- Automatic intent detection (weather vs documents)
- Fallback mechanisms for robust handling
- Real-time weather data via OpenWeather One Call API 3.0
- Smart query parsing (extracts location, date, weather type)
- Multiple query formats supported:
- "What's the weather in London?"
- "Will it rain tomorrow in Paris?"
- "Temperature in New York today"
- PDF document upload and processing
- Vector similarity search using Qdrant
- Context-aware answers with source attribution
- LangSmith integration for complete trace visibility
- Performance monitoring (latency, token usage, costs)
- Debug logging at multiple levels
- 100+ test cases covering:
- API handling and error recovery
- LLM processing and classification
- Vector retrieval and RAG chains
- End-to-end integration flows
┌─────────────────────────────────────────────────────────────┐
│ AI AGENTIC ARCHITECTURE │
└─────────────────────────────────────────────────────────────┘
🚀 USER QUERY
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 🧠 DECISION NODE - LLM CLASSIFIER (GPT-4o-mini) │
│ │
│ • Analyzes user intent │
│ • Routes to appropriate agent │
│ • Fallback: keyword matching │
└─────────────────┬───────────────────────┬───────────────────┘
│ │
Weather Query│ │Document Query
(temp, forecast)│ │(PDF, assignment)
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ 🌤️ WEATHER AGENT │ │ 📄 PDF RAG AGENT │
│ │ │ │
│ • OpenWeather API │ │ • Qdrant Vector DB │
│ • Geocoding Service │ │ • Document Embeddings │
│ • Current + Forecast │ │ • Similarity Search │
│ • 150+ countries │ │ • LangChain RetrievalQA│
└─────────┬───────────────┘ └─────────┬───────────────┘
│ │
└──────────────┬───────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ ✅ UNIFIED RESPONSE OUTPUT │
│ │
│ • Weather: Formatted forecast with conditions │
│ • Documents: RAG-based answers from uploaded PDFs │
│ • Error handling: Graceful fallbacks │
└─────────────────────────────────────────────────────────────┘
The system uses LangGraph for agent orchestration with conditional routing:
graph TD;
START([User Query]) --> DECISION{Decision Node<br/>LLM Classification}
DECISION -->|Weather| WEATHER[Weather Agent<br/>OpenWeather API]
DECISION -->|Document| PDF[PDF RAG Agent<br/>Qdrant + LangChain]
WEATHER --> END([Response])
PDF --> END
- Python 3.11+ (Download)
- pip (comes with Python)
- Git (for cloning the repository)
-
OpenAI API Key (Get it here)
- Used for: Query classification, embeddings, document QA
-
OpenWeather API Key (Get it here)
- Used for: Real-time weather data
- Free tier: 1,000 calls/day
-
LangSmith API Key (Get it here) (Optional but recommended)
- Used for: Observability and tracing
git clone https://github.com/Gangadhar24377/NeuroDynamics_langraph_agent.git
cd NeuroDynamics_langraph_agent/my_rag_appUsing Conda (Recommended):
conda create -n assignment python=3.11
conda activate assignmentUsing venv:
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
# Copy the template
cp .env.example .env
# Edit with your API keys
notepad .env # Windows
nano .env # Linux/MacAdd your API keys:
# OpenAI Configuration
OPENAI_API_KEY=sk-proj-your_openai_api_key_here
# OpenWeather Configuration
OPENWEATHERMAP_API_KEY=your_openweather_api_key_here
# LangSmith Configuration (Optional)
LANGSMITH_API_KEY=lsv2_pt_your_langsmith_api_key_here
LANGSMITH_PROJECT=NeuroDynamics_Assignment
LANGSMITH_ENDPOINT=https://api.smith.langchain.com# Test configuration
python -c "from config import *; print('✅ Configuration loaded successfully')"
---
## ⚙️ Configuration
### Environment Variables
| Variable | Required | Description | Default |
|----------|----------|-------------|---------|
| `OPENAI_API_KEY` | ✅ Yes | OpenAI API key for LLM and embeddings | - |
| `OPENWEATHERMAP_API_KEY` | ✅ Yes | OpenWeather API key for weather data | - |
| `LANGSMITH_API_KEY` | ⚠️ Optional | LangSmith API key for tracing | - |
| `LANGSMITH_PROJECT` | ⚠️ Optional | LangSmith project name | `NeuroDynamics_Assignment` |
| `LANGSMITH_ENDPOINT` | ⚠️ Optional | LangSmith API endpoint | `https://api.smith.langchain.com` |
### Vector Database
The system uses **Qdrant Cloud** for vector storage:
- **Collection**: `assignment`
- **Embedding Model**: `text-embedding-3-small` (1536 dimensions)
- **cloud required**: All data stored on Qdrant Cloud
---
## 💻 Usage
### Starting the Application
```bash
# Activate your environment
conda activate assignment # or: source venv/bin/activate
# Run the Streamlit app
streamlit run app.pyThe application will open in your browser at http://localhost:8501
- Click "Browse files" in the sidebar
- Upload PDF documents
- Click "Upload & Process"
- Documents are vectorized and stored locally
Weather Queries:
- "What's the weather in London?"
- "Will it rain tomorrow in Paris?"
- "Temperature in New York today"
Document Queries:
- "What are the requirements in the document?"
- "Tell me about the assignment"
- "What is mentioned in the PDF about AI?"
- Weather: Real-time data with temperature, conditions, humidity
- Documents: AI-generated answers from your uploaded PDFs
cd my_rag_app
python tests/run_all_tests_with_output.py# API handling tests (OpenWeather integration)
python tests/run_api_tests.py
# LLM processing tests (query classification)
python tests/run_llm_tests.py
# Retrieval logic tests (Qdrant + RAG)
python tests/run_retrieval_tests.py
# Integration tests (end-to-end flows)
python tests/run_integration_tests.pyResults are saved in tests/tests_results/:
api_handling_results.txtllm_processing_results.txtretrieval_logic_results.txtintegration_results.txtmaster_summary.txt
- 100+ test cases total
- API Handling: 30+ tests (error handling, mocking, validation)
- LLM Processing: 25+ tests (classification, fallbacks, consistency)
- Retrieval Logic: 35+ tests (vector DB, RAG chains, performance)
- Integration: 15+ tests (end-to-end flows, state management)
my_rag_app/
│
├── app.py # Streamlit web interface
├── config.py # Configuration and environment variables
├── requirements.txt # Python dependencies
├── .env # API keys (not in git)
├── README.md # This file
│
├── nodes/ # LangGraph agent nodes
│ ├── decision_node.py # LLM-based query classifier
│ ├── weather_node.py # Weather API integration
│ └── pdf_rag_node.py # Document RAG agent
│
├── graph/ # LangGraph setup
│ └── graph_setup.py # Graph builder and configuration
│
│── Langsmith_evals/ # contains langsmith screenshots fo each node with its outputs
│ └──PDF_RAG_NODE/ # contains pdf_rag_node screenshots
│ └──WEATHER_NODE/ # contains weather_node screenshots
├── rag/ # RAG components
│ ├── ingestion.py # Document processing and chunking
│ ├── retriever.py # Vector store and retrieval
│ └── prompts.py # RAG prompts and templates
│
├── utils/ # Utility modules
│ └── query_processor.py # Smart query parsing
│
├── tests/ # Test suite
│ ├── test_api_handling.py # API tests
│ ├── test_llm_processing.py # LLM tests
│ ├── test_retrieval_logic.py # RAG tests
│ ├── test_integration.py # Integration tests
│ ├── run_all_tests_with_output.py # Test runner
│ └── tests_results/ # Test output files
│
├── local_qdrant/ # Local vector database
│ └── collection/
│ └── documents/
│
└── data/ # Sample documents
└── Assignment - AI Engineer.pdf
Decision Node (Query Routing) Features:
- Uses
GPT-4o-minifor fast, cost-effective classification - Fallback to keyword matching if LLM fails
- Updates state with routing decision
Weather Node Features:
- Smart query parsing (extracts location, date, weather type)
- Geocoding support for 150+ countries
- Error handling for invalid cities, API failures
- Formatted, human-readable responses
PDF RAG Node Features:
- Local Qdrant vector database
- Similarity search with top-k retrieval
- Context-aware answers using RetrievalQA
- Document count checking
Document Ingestion Features:
- Recursive character splitting for optimal chunking
- OpenAI embeddings (text-embedding-3-small)
- Metadata preservation
- Chunk overlap for context continuity
Endpoint: https://api.openweathermap.org/data/3.0/onecall
Parameters:
lat,lon: Geographic coordinatesappid: API keyunits:metric(Celsius) orimperial(Fahrenheit)exclude: Optional data exclusions
Response: Current weather, hourly/daily forecasts, alerts
Models Used:
- GPT-4o-mini: Query classification, document QA
- text-embedding-3-small: Document embeddings (1536 dimensions)
Cost Optimization:
- Using
gpt-4o-miniinstead ofgpt-4for routing (10x cheaper) - Token usage: ~150 tokens/query for classification
- Cost: ~$0.0002 per RAG query
Error: 401 Unauthorized or API key is not configured
Solution:
# Check .env file exists
ls -la .env
# Verify API keys are loaded
python -c "from config import *; print('OpenAI:', bool(OPENAI_API_KEY)); print('Weather:', bool(OPENWEATHER_API_KEY))"
# Test API connectivity
python test.pyError: ModuleNotFoundError: No module named 'langchain'
Solution:
# Ensure environment is activated
conda activate assignment
# Reinstall dependencies
pip install -r requirements.txtError: Could not connect to Qdrant
Solution:
# Check local_qdrant directory exists
ls -la local_qdrant/
# Recreate collection
python -c "from rag.retriever import ensure_collection_exists; ensure_collection_exists()"Error: Address already in use
Solution:
# Use a different port
streamlit run app.py --server.port 8502
# Or kill the existing process (Windows)
netstat -ano | findstr :8501
taskkill /PID <PID> /F| Operation | Latency | Tokens | Cost/Query |
|---|---|---|---|
| Query Classification | 1-2s | ~150 | $0.00003 |
| Weather Query (Full) | 2-4s | ~150 | $0.00003 |
| Document Query (RAG) | 8-12s | ~1,170 | $0.00024 |
| Document Upload | 5-10s | Varies | Per doc |
- Use GPT-4o-mini for classification (10x cheaper than GPT-4)
- Cache embeddings for frequently queried documents
- Adjust chunk size (smaller = faster but less context)
- Limit top-k in retrieval (fewer docs = faster responses)
- Enable LangSmith to identify bottlenecks
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests before committing
python tests/run_all_tests_with_output.py
# Format code
black .
isort .- LangChain for the amazing RAG framework
- LangGraph for agent orchestration
- OpenAI for GPT and embedding models
- Qdrant for vector database
- OpenWeather for weather data API
- Streamlit for the web interface
- GitHub: @Gangadhar24377
- Issues: GitHub Issues
- Email: [gangadharkambhamettu@gmail.com]
- Add more specialized agents (news, stocks, etc.)
- Implement conversation memory
- Support multiple languages
- Add voice input/output
- Deploy to cloud (AWS/Azure/GCP)
- Add user authentication
- Implement caching layer
- Add analytics dashboard
Built using LangGraph, LangChain, and OpenAI
⭐ Star this repo if you find it helpful!