| title | emoji | colorFrom | colorTo | sdk | app_port | pinned | license |
|---|---|---|---|---|---|---|---|
LLM Analysis Quiz Solver |
🤖 |
blue |
red |
docker |
7860 |
false |
mit |
An intelligent, autonomous agent built with LangGraph and LangChain that solves data-related quizzes involving web scraping, data processing, analysis, and visualization tasks. The system uses Google's Gemini 2.5 Flash model to orchestrate tool usage and make decisions.
- Overview
- Architecture
- Features
- Project Structure
- Installation
- Configuration
- Usage
- API Endpoints
- Tools & Capabilities
- Docker Deployment
- How It Works
- License
This project was developed for the TDS (Tools in Data Science) course project, where the objective is to build an application that can autonomously solve multi-step quiz tasks involving:
- Data sourcing: Scraping websites, calling APIs, downloading files
- Data preparation: Cleaning text, PDFs, and various data formats
- Data analysis: Filtering, aggregating, statistical analysis, ML models
- Data visualization: Generating charts, narratives, and presentations
The system receives quiz URLs via a REST API, navigates through multiple quiz pages, solves each task using LLM-powered reasoning and specialized tools, and submits answers back to the evaluation server.
The project uses a LangGraph state machine architecture with the following components:
┌─────────────┐
│ FastAPI │ ← Receives POST requests with quiz URLs
│ Server │
└──────┬──────┘
│
▼
┌─────────────┐
│ Agent │ ← LangGraph orchestrator with Gemini 2.5 Flash
│ (LLM) │
└──────┬──────┘
│
├────────────┬────────────┬─────────────┬──────────────┐
▼ ▼ ▼ ▼ ▼
[Scraper] [Downloader] [Code Exec] [POST Req] [Add Deps]
- FastAPI Server (
main.py): Handles incoming POST requests, validates secrets, and triggers the agent - LangGraph Agent (
agent.py): State machine that coordinates tool usage and decision-making - Tools Package (
tools/): Modular tools for different capabilities - LLM: Google Gemini 2.5 Flash with rate limiting (9 requests per minute)
- ✅ Autonomous multi-step problem solving: Chains together multiple quiz pages
- ✅ Dynamic JavaScript rendering: Uses Playwright for client-side rendered pages
- ✅ Code generation & execution: Writes and runs Python code for data tasks
- ✅ Flexible data handling: Downloads files, processes PDFs, CSVs, images, etc.
- ✅ Self-installing dependencies: Automatically adds required Python packages
- ✅ Robust error handling: Retries failed attempts within time limits
- ✅ Docker containerization: Ready for deployment on HuggingFace Spaces or cloud platforms
- ✅ Rate limiting: Respects API quotas with exponential backoff
LLM-Analysis-TDS-Project-2/
├── agent.py # LangGraph state machine & orchestration
├── main.py # FastAPI server with /solve endpoint
├── pyproject.toml # Project dependencies & configuration
├── Dockerfile # Container image with Playwright
├── .env # Environment variables (not in repo)
├── tools/
│ ├── __init__.py
│ ├── web_scraper.py # Playwright-based HTML renderer
│ ├── code_generate_and_run.py # Python code executor
│ ├── download_file.py # File downloader
│ ├── send_request.py # HTTP POST tool
│ └── add_dependencies.py # Package installer
└── README.md
- Python 3.12 or higher
- uv package manager (recommended) or pip
- Git
git clone https://github.com/saivijayragav/LLM-Analysis-TDS-Project-2.git
cd LLM-Analysis-TDS-Project-2Ensure you have uv installed, then sync the project:
# Install uv if you haven't already
pip install uv
# Sync dependencies
uv sync
uv run playwright install chromium
Start the FastAPI server:
uv run main.py
The server will start at http://0.0.0.0:7860.
# Create virtual environment
python -m venv venv
.\venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Install dependencies
pip install -e .
# Install Playwright browsers
playwright install chromiumCreate a .env file in the project root:
# Your credentials from the Google Form submission
EMAIL=[email protected]
SECRET=your_secret_string
# Google Gemini API Key
GOOGLE_API_KEY=your_gemini_api_key_here- Visit Google AI Studio
- Create a new API key
- Copy it to your
.envfile
Start the FastAPI server:
# If using uv
uv run main.py
# If using standard Python
python main.pyThe server will start on http://0.0.0.0:7860
Send a POST request to test your setup:
curl -X POST http://localhost:7860/solve \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"secret": "your_secret_string",
"url": "https://tds-llm-analysis.s-anand.net/demo"
}'Expected response:
{
"status": "ok"
}The agent will run in the background and solve the quiz chain autonomously.
Receives quiz tasks and triggers the autonomous agent.
Request Body:
{
"email": "[email protected]",
"secret": "your_secret_string",
"url": "https://example.com/quiz-123"
}Responses:
| Status Code | Description |
|---|---|
200 |
Secret verified, agent started |
400 |
Invalid JSON payload |
403 |
Invalid secret |
Health check endpoint for monitoring.
Response:
{
"status": "ok",
"uptime_seconds": 3600
}The agent has access to the following tools:
- Uses Playwright to render JavaScript-heavy pages
- Waits for network idle before extracting content
- Returns fully rendered HTML for parsing
- Downloads files (PDFs, CSVs, images, etc.) from direct URLs
- Saves files to
LLMFiles/directory - Returns the saved filename
- Executes arbitrary Python code in an isolated subprocess
- Returns stdout, stderr, and exit code
- Useful for data processing, analysis, and visualization
- Sends JSON payloads to submission endpoints
- Includes automatic error handling and response parsing
- Prevents resubmission if answer is incorrect and time limit exceeded
- Dynamically installs Python packages as needed
- Uses
uv addfor fast package resolution - Enables the agent to adapt to different task requirements
docker build -t llm-analysis-agent .docker run -p 7860:7860 \
-e EMAIL="[email protected]" \
-e SECRET="your_secret_string" \
-e GOOGLE_API_KEY="your_api_key" \
llm-analysis-agent- Create a new Space with Docker SDK
- Push this repository to your Space
- Add secrets in Space settings:
EMAILSECRETGOOGLE_API_KEY
- The Space will automatically build and deploy
- FastAPI receives a POST request with quiz URL
- Validates the secret against environment variables
- Returns 200 OK and starts the agent in the background
- LangGraph creates a state machine with two nodes:
agentandtools - The initial state contains the quiz URL as a user message
The agent follows this loop:
┌─────────────────────────────────────────┐
│ 1. LLM analyzes current state │
│ - Reads quiz page instructions │
│ - Plans tool usage │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 2. Tool execution │
│ - Scrapes page / downloads files │
│ - Runs analysis code │
│ - Submits answer │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 3. Response evaluation │
│ - Checks if answer is correct │
│ - Extracts next quiz URL (if exists) │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 4. Decision │
│ - If new URL exists: Loop to step 1 │
│ - If no URL: Return "END" │
└─────────────────────────────────────────┘
- All messages (user, assistant, tool) are stored in state
- The LLM uses full history to make informed decisions
- Recursion limit set to 200 to handle long quiz chains
- Agent returns "END" when no new URL is provided
- Background task completes
- Logs indicate success or failure
- LangGraph over Sequential Execution: Allows flexible routing and complex decision-making
- Background Processing: Prevents HTTP timeouts for long-running quiz chains
- Tool Modularity: Each tool is independent and can be tested/debugged separately
- Rate Limiting: Prevents API quota exhaustion (9 req/min for Gemini)
- Code Execution: Dynamically generates and runs Python for complex data tasks
- Playwright for Scraping: Handles JavaScript-rendered pages that
requestscannot - uv for Dependencies: Fast package resolution and installation
This project is licensed under the MIT License. See the LICENSE file for details.
Author: Sathish Kesavan Course: Tools in Data Science Institution: IIT Madras