fablefrost/YantraSolve
<div align="center">
π§© YantraSolve
AI-Powered Autonomous Quiz Solver
   
Features β’ Quick Start β’ API β’ Architecture β’ Configuration β’ Testing
</div>
π Overview
YantraSolve is an autonomous AI agent that solves data-driven quizzes using a state machine workflow. Built for the Tools in Data Science β Project 2 (IITM BS Degree Programme).
π Workflow
The application uses a LangGraph state machine to orchestrate the solving process:
- Fetch Context: The agent visits the quiz URL using a headless browser (Playwright) to capture HTML, text, console logs, and a screenshot.
- Agent Reasoning: An LLM (GPT-4o or similar) analyzes the page context and decides the next step.
- Tool Execution: If the agent needs to calculate something, download a file, or analyze an image, it calls the appropriate tool.
- Submission: Once the answer is determined, the agent submits it to the server.
- Feedback Loop: The system checks the submission result.
- Correct: The agent proceeds to the next quiz URL.
- Incorrect: The agent retries with the error feedback (up to 10 attempts).
- Timeout: If the quiz takes too long, it skips to the next one.
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββ
β fetch_contextββββββΆβ agent_reasoning ββββββΆβ execute_tools β
βββββββββββββββ ββββββββββ¬βββββββββ βββββββββββββββββ
β
ββββββββββΌβββββββββ
β submit_answer β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ ββββββββββββββββ
βprocess_feedback ββββββΆβ next quiz/ENDβ
βββββββββββββββββββ βββββββββββββββββ¨ Features
Agent Tools
Capabilities
Reliability
- β±οΈ 3-minute timeout per quiz with auto-skip
- π 10 retry attempts before moving on
- π Round-robin API key rotation for Gemini
- πΎ File-based caching with TTL
- π‘οΈ Graceful error handling - agent never crashes
π Quick Start
Prerequisites
- Python 3.12+
- uv (recommended) or pip
- Docker (optional, for containerized run)
Installation (Local)
# Clone repository
git clone https://github.com/Khushi-Choudhary11/yantrasolve.git
cd yantrasolve
# Install dependencies
uv sync # or: pip install -e .
# Install browser
playwright install chromiumInstallation (Docker)
# Build image
docker build -t yantrasolve .
# Run container
docker run --env-file .env -p 8000:8000 yantrasolveConfiguration
Create a .env file:
# Required
SECRET_KEY=your-secret-key
STUDENT_EMAIL=your-email@ds.study.iitm.ac.in
# Primary LLM: Gemini 1.5 Flash (with round-robin keys and $300 free trial credits)
GEMINI_API_KEYS=key1,key2,key3
LLM_PROVIDER=google
LLM_MODEL=gemini-1.5-flash
# Fallback LLM: AIPipe (used if Gemini fails)
AIPIPE_API_KEY=your-aipipe-token
AIPIPE_BASE_URL=https://aipipe.org/openrouter/v1
AIPIPE_MODEL=google/gemini-1.5-flash:free
# Server
HOST=0.0.0.0
PORT=8000
DEBUG=falseRun
# Development
uv run python main.py
# Production
uv run uvicorn main:app --host 0.0.0.0 --port 8000π‘ API Reference
Health Check
GET /
GET /healthResponse: 200 OK
{"status": "ok", "message": "Quiz Solver is running"}Submit Quiz
POST /quiz
Content-Type: application/jsonRequest:
{
"email": "student@example.com",
"secret": "your-secret-key",
"url": "https://example.com/quiz/1"
}Response: | Status | Description | |--------|-------------| | 200 | Quiz solving started (background) | | 400 | Invalid JSON payload | | 403 | Invalid secret or email |
ποΈ Architecture
yantrasolve/
βββ main.py # FastAPI application
βββ app/
β βββ config/
β β βββ settings.py # Pydantic settings
β βββ graph/
β β βββ graph.py # LangGraph workflow
β β βββ state.py # QuizState TypedDict
β β βββ resources.py # Global resources
β βββ nodes/
β β βββ fetch.py # Page fetching
β β βββ agent.py # AI reasoning
β β βββ tools.py # Tool execution
β β βββ submit.py # Answer submission
β β βββ feedback.py # Response handling
β βββ tools/
β β βββ python.py # Python sandbox
β β βββ javascript.py # Browser JS
β β βββ download.py # File downloader
β β βββ call_llm.py # Gemini multimodal
β β βββ submit_answer.py
β βββ resources/
β β βββ llm.py # Multi-provider LLM
β β βββ browser.py # Playwright wrapper
β β βββ api.py # HTTP client
β βββ utils/
| βββ answers.py # Save correct answers
β βββ cache.py # File-based caching
β βββ gemini.py # Gemini utilities
β βββ helpers.py # Temp file management
β βββ logging.py # Loguru setup
βββ tests/ # Pytest suite
βββ Dockerfile
βββ pyproject.tomlβοΈ Configuration
π³ Docker
# Build
docker build -t yantrasolve .
# Run
docker run -p 8000:8000 \
-e SECRET_KEY=xxx \
-e STUDENT_EMAIL=xxx \
-e GEMINI_API_KEYS=key1,key2,key3 \
-e AIPIPE_API_KEY=xxx \
yantrasolveHugging Face Spaces
- Create a new Space with Docker SDK
- Push this repository
- Add secrets in Space settings:
GEMINI_API_KEYS(comma-separated, e.g.,key1,key2,key3)AIPIPE_API_KEYSTUDENT_EMAILSECRET_KEY- Access via
https://your-space.hf.space/quiz
π§ͺ Testing
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=app
# Run specific module
uv run pytest tests/test_tools/ -vTest coverage: 225 tests covering all modules.
πΊοΈ Roadmap
- [ ] Dynamic model selection per quiz type
- [ ] Parallel quiz processing
- [ ] Web UI for monitoring progress
- [ ] Performance metrics dashboard
- [ ] Enhanced geo-spatial analysis
π License
This project is licensed under the MIT License - see the LICENSE file.
π€ Author
Khushi Choudhary
- π§ Email: 23f3002872@ds.study.iitm.ac.in
- π GitHub: @Khushi-Choudhary11
