UFAC (Uncertainity Β· First Β· Agent Β· Council) is a multi-agent LLM reasoning framework that determines a farmer's eligibility for India's PM-KISAN βΉ6,000/year direct benefit scheme using a council of 5 specialized AI agents working in parallel.
- β¨ Features
- ποΈ Architecture
- π€ The 5 Agents
- π Performance
- π Quick Start
- π API Reference
- π Project Structure
- π Security
- π§ͺ Testing
- βοΈ Configuration
- π οΈ Troubleshooting
- π₯ Team
|
|
|
|
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER BROWSER β
β Next.js 15 Β· ufac.vercel.app β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β POST /check
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β Rate Limiting Β· CORS Β· Cache β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββ βββββββββββββββββββββββ
β UFAC Engine β β RAG Pipeline β
β Orchestrator βββββββββββββββββββΊβ ChromaDB + Rules β
ββββββββββ¬ββββββββββββ βββββββββββββββββββββββ
β
βΌ asyncio parallel execution
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT COUNCIL β
β β
β BATCH 1 (parallel) BATCH 2 (parallel) β
β ββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββ β
β β Fact β β Assumption β β Confidence β βDecision β β
β β Agent β β Agent β β Agent β β Agent β β
β ββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββ β
β ββββββββββββ β
β β Unknown β β
β β Agent β β
β ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
UFAC Response: answer Β· confidence Β· facts Β· assumptions Β·
unknowns Β· risk_level Β· next_steps Β· consensus
| Agent | Role | Output |
|---|---|---|
| π Fact Agent | Extracts confirmed, objective facts from the user's input | known_facts[] |
| π Assumption Agent | Identifies implicit assumptions being made | assumptions[] |
| β Unknown Agent | Detects missing critical information that could change the verdict | unknowns[] |
| π Confidence Agent | Calculates a 0β100 confidence score based on available data | confidence score |
| β Decision Agent | Generates the final verdict and actionable next steps | answer, next_steps[] |
Each agent runs 3Γ independently and the results are consensus-aggregated β meaning the final answer reflects agreement across all runs, reducing hallucination.
v1.0 v2.0 Improvement
βββββββββ βββββββββ ββββββββββββββ
First request 45s 8β10s π’ 4.5Γ faster
Cached request 45s 0.1s π’ 450Γ faster
RAG load time 10s 2s π’ 5Γ faster
Avg (80% cache) 45s 0.5s π’ 90Γ faster
Cache hit rate 0% 80%+ π’ β improvement
- Python 3.9+
- Node.js 18+
- Groq API key β console.groq.com/keys
git clone https://github.com/Arjun-57561/UFAC.git
cd UFAC
# Copy and fill in your API key
cp .env.example .env
# Edit .env β add GROQ_API_KEY=gsk_...# Install dependencies
pip install -r requirements.txt
# (Optional) Setup RAG vector database
python setup_rag.py
# Start API server
python -m uvicorn api.app:app --reload
# β http://localhost:8000
# β http://localhost:8000/docs (Swagger UI)cd UI
npm install
npm run dev
# β http://localhost:3000π‘ That's it. Open
http://localhost:3000, fill in the form, and watch the 5 agents assess eligibility in real-time.
Request:
{
"occupation": "farmer",
"land_ownership": "yes",
"aadhaar_linked": true,
"aadhaar_ekyc": true,
"bank_account": true,
"annual_income": 180000,
"income_tax_payer": false,
"government_employee": false,
"monthly_pension_above_10k": false,
"practicing_professional": false,
"constitutional_post": false
}Response:
{
"answer": "ELIGIBLE for PM-KISAN",
"confidence": 92,
"known_facts": ["User is a farmer", "User owns agricultural land"],
"assumptions": ["Land is self-cultivated, not leased out"],
"unknowns": ["Land size not specified"],
"risk_level": "LOW",
"next_steps": ["Register at pmkisan.gov.in", "Submit land records (Khasra/Khatauni)"],
"fact_consensus": 0.91,
"confidence_consensus": 0.88
}| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check + RAG status |
GET |
/metrics |
Request counts, latency, errors |
GET |
/cache-stats |
Hit rate, memory usage |
GET |
/circuit-status |
Circuit breaker state |
GET |
/history |
Past assessments (paginated) |
GET |
/history/{id} |
Full assessment by ID |
POST |
/cache-clear |
Flush all caches |
GET |
/docs |
Swagger UI |
UFAC/
βββ π api/
β βββ app.py # FastAPI app β routing, middleware, rate limiting
β
βββ π core/
β βββ fact_agent.py # Agent: extracts known facts
β βββ assumption_agent.py # Agent: identifies assumptions
β βββ unknown_agent.py # Agent: detects missing info
β βββ confidence_agent.py # Agent: scores confidence 0β100
β βββ decision_agent.py # Agent: final verdict + next steps
β βββ ufac_engine.py # Orchestrator β runs agents in parallel
β βββ llm_utils.py # Groq API wrapper with retry + circuit breaker
β βββ cache.py # In-memory TTL cache
β βββ metrics.py # Request/latency/error tracking
β βββ circuit_breaker.py # Circuit breaker pattern
β βββ database.py # SQLite/PostgreSQL persistence
β βββ constants.py # Centralized config (no magic numbers)
β βββ schema.py # Pydantic response schemas
β
βββ π data/
β βββ rag_pipeline.py # RAG with singleton + fallback
β βββ pm_kisan_rules.py # Hard-coded eligibility rules (fallback)
β βββ chroma_db/ # ChromaDB vector store
β
βββ π UI/ # Next.js 15 frontend
β βββ app/ # App Router pages
β β βββ page.tsx # Home / landing
β β βββ check/page.tsx # Eligibility form + results
β β βββ flow/page.tsx # Agent flow visualization
β β βββ about/page.tsx # About page
β βββ components/ # Reusable React components
β βββ hooks/ # useUFACAssessment, useBackendStatus
β βββ lib/ # API client, constants, utils
β
βββ π tests/ # 30+ unit tests
βββ π requirements.txt
βββ π .env.example
βββ π README.md
| Feature | Implementation | Status |
|---|---|---|
| CORS lockdown | ALLOWED_ORIGINS env var |
β |
| Rate limiting | 10 req/min on /check |
β |
| Input sanitization | Injection pattern regex | β |
| Security headers | X-Frame, XSS, MIME | β |
| Circuit breaker | 5 failures β 60s pause | β |
| Exponential backoff | 3 retries with tenacity | β |
| No secrets in logs | Env-based config only | β |
# Run full test suite
pytest tests/ -v
# With coverage report
pytest tests/ --cov=core --cov=api --cov-report=html
# Individual test files
pytest tests/test_cache.py # Cache layer
pytest tests/test_error_handling.py # Error handling
pytest tests/test_api.py # API endpoints30+ unit tests across cache, error handling, and API endpoints.
Create a .env file (copy from .env.example):
# ββ Required ββββββββββββββββββββββββββββββββββββββ
GROQ_API_KEY=gsk_your_key_here
# ββ Security ββββββββββββββββββββββββββββββββββββββ
ALLOWED_ORIGINS=http://localhost:3000,https://ufac.vercel.app
# ββ Performance βββββββββββββββββββββββββββββββββββ
LLM_TIMEOUT_SECONDS=15.0
CACHE_TTL_ASSESSMENT=3600 # 1 hour
CACHE_TTL_RAG=7200 # 2 hours
CACHE_TTL_LLM=3600 # 1 hour
# ββ Database ββββββββββββββββββββββββββββββββββββββ
DATABASE_URL=sqlite+aiosqlite:///./ufac_engine.db
# ββ Development βββββββββββββββββββββββββββββββββββ
DEV_MODE=true # Uses 1 LLM call instead of 3
LOG_LEVEL=INFOβ Backend won't start
- Check
GROQ_API_KEYis set correctly in.env - Verify port 8000 is free:
lsof -i :8000 - Check
ALLOWED_ORIGINSincludes your frontend URL
β Rate limit errors (HTTP 429)
- Wait 60 seconds between bursts
- Check current counts at
GET /metrics - Use
DEV_MODE=trueduring development
β Circuit breaker open
- Check
GET /circuit-status - Verify your Groq API key is valid and has quota
- Circuit auto-recovers after 60 seconds
β RAG not working
- Run
python setup_rag.pyto build the vector DB - Check
GET /rag-statusfor details - System falls back to hardcoded rules automatically
β Frontend shows blank page
- Check browser console for errors
- Ensure backend is running on port 8000
- Verify
NEXT_PUBLIC_API_URLinUI/.env.local
BTech AIML Β· PBL-2 Project Β· 2023β2027 Batch
| Role | Contribution |
|---|---|
| π§βπ» Backend & AI Architecture | UFAC engine, agents, RAG pipeline, FastAPI |
| π¨ Frontend Development | Next.js UI, components, animations |
| π Data & Rules | PM-KISAN ruleset, ChromaDB, preprocessing |
| π§ͺ Testing & DevOps | Test suite, Vercel deployment, CI |
UFAC Engine v2.0 β Production-ready since April 2026
π Live Site Β Β·Β π API Docs Β Β·Β π Report Bug