Skip to content

ayushchaware08/multi_agent_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Multi-Agent System πŸ€–

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

alt text

πŸ› οΈ Technical Details

Key Technologies

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

πŸ—οΈ System Architecture

alt text

🏒 Project Structure

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

Performance Optimizations

  1. Batch Processing: Large PDFs processed in chunks to prevent hanging
  2. Async Processing: Non-blocking API with background tasks
  3. Model Caching: Embedding models cached for faster inference
  4. Connection Pooling: Efficient database connections
  5. Retry Mechanisms: Robust error handling with exponential backoff

πŸ”§ Core Agents

1. PDF RAG Agent πŸ“„

  • 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

2. ArXiv Research Agent πŸ“š

  • 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

3. Web Search Agent 🌐

  • 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

πŸ”— API Documentation

The system exposes a RESTful API with the following key endpoints:

Core Endpoints

1. Query Processing

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

2. PDF Upload & Processing

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"
}

3. Upload Status Check

GET /upload/status/{doc_id} - Check processing status

Sample Response:

{
    "status": "completed",
    "message": "Successfully ingested 45 chunks",
    "chunks_count": 45,
    "completed_at": 1703123456
}

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/ayushchaware08/multi_agent_system.git
    cd multi_agent_system
  2. Set up virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\\Scripts\\activate
  3. Install dependencies

    cd backend
    pip install -r requirements.txt
  4. Configure environment

    cp .env.example .env
    # Edit .env file with your API keys
  5. Create required directories

    mkdir -p data/uploads data/vectorstore logs

Running the System

Option 1: Full System (Recommended)

  1. Start Backend

    cd backend
    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
  2. Start Frontend (New terminal)

    cd frontend
    streamlit run streamlit_app.py

πŸ“ Environment Configuration

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=8000

πŸ”— API Documentation

Core Endpoints

1. Query Processing

POST /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
  }
}

2. PDF Upload & Processing

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"
}

3. Upload Status Check

GET /upload/status/{doc_id}

Response:
{
  "status": "completed",  // processing, completed, failed
  "message": "Successfully ingested 45 chunks",
  "chunks_count": 45,
  "completed_at": 1703123456
}

4. System Health

GET /health

Response:
{
  "status": "healthy",
  "embedding_model": "loaded"
}

Additional Endpoints

  • GET /upload/list - List all uploaded documents
  • DELETE /upload/{doc_id} - Delete uploaded document
  • GET /logs/ - View system decision logs
  • DELETE /upload/clear-failed - Clear failed uploads

🎯 Usage Examples

1. Academic Research

Query: "recent papers on transformer architectures in 2025"
β†’ Routes to ArXiv Agent
β†’ Returns: Latest papers with analysis and recommendations

2. PDF Document Analysis

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

3. Current Information

Query: "What happened in the tech industry this week?"
β†’ Routes to Web Search Agent  
β†’ Returns: Latest news with multiple source synthesis

4. Mixed Queries

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

πŸš€ Deployment

Production Deployment on Render This application is deployed on Render with separate services for backend and frontend. Steps:

  1. Containerized the FastAPI backend using Docker.
  2. Linked the GitHub repository to Render for CI/CD integration.
  3. Configured environment variables for API keys and secrets.
  4. Set the web service to auto-deploy on main branch updates.
  5. Utilized Render’s autoscaling and HTTPS configuration.

Live Demo

πŸ“„ License

MIT License - see LICENSE file for details.

Made by ayushchaware08

About

multi-agent AI system that intelligently routes user queries to specialized agents for optimal answers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors