A sophisticated multi-agent AI system that intelligently routes user queries to specialized agents for optimal answers. The system combines PDF processing, academic research, and web search capabilities with intelligent routing powered by Groq LLM.
Live Demo https://multi-agent-system-eosin.vercel.app/
Video Demo: https://youtu.be/Iu5QKyXwKVk
- Backend Framework: FastAPI (async/await, automatic OpenAPI docs)
- Frontend: Streamlit (rapid prototyping, file uploads)
- LLM: Groq (fast inference, multiple models)
- Integration Framework: LangChain (document processing, agent orchestration)
- Vector Database: FAISS
- Embeddings: HuggingFace Transformers (local, no API costs)
- PDF Processing: PyMuPDF (fast, reliable text extraction)
- Web Search: SerpAPI (Google Search API)
- Academic Search: ArXiv API (open academic papers)
multi_agent_system/
βββ backend/ # FastAPI Backend
β βββ app/
β β βββ main.py # FastAPI application entry
β β βββ api/ # API route handlers
β β β βββ ask.py # Main query processing
β β β βββ upload.py # PDF upload & status
β β β βββ logs.py # System logs
β β βββ agents/ # Specialized AI agents
β β β βββ controller.py # Intelligent routing
β β β βββ pdf_rag.py # PDF document processing
β β β βββ arxiv_agent.py # Academic paper search
β β β βββ web_search.py # Web search & synthesis
β β βββ utils/ # Shared utilities
β β βββ logging_utils.py # Decision logging
β β βββ security.py # Upload validation
β β βββ backoff_utils.py # Retry mechanisms
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment template
β βββ data/ # Data storage
β βββ uploads/ # Uploaded PDFs
β βββ vectorstore/ # FAISS storage
βββ frontend/ # Streamlit Frontend
β βββ streamlit_app.py # User interface
βββ logs/ # System logs
β βββ decision_logs.jsonl # Agent routing decisions
βββ sample_pdf/ # sample pdf to test RAG
β βββ.pdf file
βββ .gitignore # Git ignore patterns
βββ REPORT.pdf # Project report
βββ render.yaml # Render deployment config
βββ README.md # This file
- Batch Processing: Large PDFs processed in chunks to prevent hanging
- Async Processing: Non-blocking API with background tasks
- Model Caching: Embedding models cached for faster inference
- Connection Pooling: Efficient database connections
- Retry Mechanisms: Robust error handling with exponential backoff
- Purpose: Answer questions about uploaded PDF documents
- Technology: LangChain + FAISS + HuggingFace Embeddings
- Features:
- PDF text extraction using PyMuPDF
- Intelligent text chunking with overlap
- Batch processing for large documents (prevents hanging)
- Vector similarity search with metadata filtering
- Document-specific or global PDF search
- Purpose: Find and analyze recent academic papers
- Technology: ArXiv API + Groq LLM analysis
- Features:
- Smart query preprocessing and field-specific search
- Recent paper filtering (18-month window)
- Comprehensive paper analysis with structured output
- Research trend identification
- Direct ArXiv links and paper recommendations
- Purpose: Current information and general web queries
- Technology: SerpAPI (Google Search) + Groq LLM synthesis
- Features:
- Real-time Google search results
- Multi-source information synthesis
- Structured answer generation
- Source attribution and transparency
The system exposes a RESTful API with the following key endpoints:
POST /ask/ - Process user queries and route to appropriate agents
Sample Request:
{
"text": "What are recent developments in AI safety?",
"pdf_doc_id": "upload_1703123456",
"prefer_agent": "ARXIV"
}Sample Response:
{
"answer": "Recent developments in AI safety include constitutional AI methods, RLHF improvements, and robustness testing frameworks...",
"agents_used": "ARXIV",
"rationale": "User asked about recent papers in AI safety",
"trace": {
"papers": ["Paper 1", "Paper 2"],
"query": "AI safety developments 2024",
"llm_duration": 2.34
}
}POST /upload/ - Upload PDF documents for processing
Sample Response:
{
"status": "accepted",
"doc_id": "upload_1703123456",
"filename": "research_paper.pdf",
"check_status": "/upload/status/upload_1703123456"
}GET /upload/status/{doc_id} - Check processing status
Sample Response:
{
"status": "completed",
"message": "Successfully ingested 45 chunks",
"chunks_count": 45,
"completed_at": 1703123456
}- Python 3.8+
- API Keys:
- Groq API Key (Required)
- SerpAPI Key (Optional - for web search)
-
Clone the repository
git clone https://github.com/ayushchaware08/multi_agent_system.git cd multi_agent_system -
Set up virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\\Scripts\\activate
-
Install dependencies
cd backend pip install -r requirements.txt -
Configure environment
cp .env.example .env # Edit .env file with your API keys -
Create required directories
mkdir -p data/uploads data/vectorstore logs
-
Start Backend
cd backend uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 -
Start Frontend (New terminal)
cd frontend streamlit run streamlit_app.py
Create a .env file in the backend directory:
GROQ_API_KEY=your_groq_api_key_here
SERPAPI_API_KEY=your_serpapi_key_here
CHROMA_DB_DIR=data/vectorstore
MAX_UPLOAD_MB=10
LOG_FILE=logs/decision_logs.jsonl
FASTAPI_HOST=0.0.0.0
FASTAPI_PORT=8000POST /ask/
Content-Type: application/json
{
"text": "What are recent developments in AI safety?",
"pdf_doc_id": "optional_document_id",
"prefer_agent": "ARXIV" // Optional: PDF_RAG, ARXIV, WEB_SEARCH
}
Response:
{
"answer": "Detailed AI-generated response...",
"agents_used": "ARXIV",
"rationale": "User asked about recent papers",
"trace": {
"papers": [...],
"query": "...",
"llm_duration": 2.34
}
}POST /upload/
Content-Type: multipart/form-data
FormData: file=@document.pdf
Response:
{
"status": "accepted",
"doc_id": "upload_1703123456",
"filename": "document.pdf",
"check_status": "/upload/status/upload_1703123456"
}GET /upload/status/{doc_id}
Response:
{
"status": "completed", // processing, completed, failed
"message": "Successfully ingested 45 chunks",
"chunks_count": 45,
"completed_at": 1703123456
}GET /health
Response:
{
"status": "healthy",
"embedding_model": "loaded"
}GET /upload/list- List all uploaded documentsDELETE /upload/{doc_id}- Delete uploaded documentGET /logs/- View system decision logsDELETE /upload/clear-failed- Clear failed uploads
Query: "recent papers on transformer architectures in 2025"
β Routes to ArXiv Agent
β Returns: Latest papers with analysis and recommendations
1. Upload PDF via frontend or API
2. Query: "What are the main conclusions of the uploaded document?"
β Routes to PDF RAG Agent
β Returns: Document-specific insights with source citations
Query: "What happened in the tech industry this week?"
β Routes to Web Search Agent
β Returns: Latest news with multiple source synthesis
Query: "Compare recent AI safety papers with regulations mentioned in my uploaded policy document"
β Controller intelligently routes to multiple agents
β Returns: Comprehensive analysis from multiple sources
Production Deployment on Render This application is deployed on Render with separate services for backend and frontend. Steps:
- Containerized the FastAPI backend using Docker.
- Linked the GitHub repository to Render for CI/CD integration.
- Configured environment variables for API keys and secrets.
- Set the web service to auto-deploy on main branch updates.
- Utilized Renderβs autoscaling and HTTPS configuration.
Live Demo
- Backend API: https://multi-agent-backend-n3bp.onrender.com
- Frontend UI: https://multi-agent-system-frontend.onrender.com
MIT License - see LICENSE file for details.
Made by ayushchaware08

