point9/BOQ_of_Tenders_Agent
0
BOQTenders - Bill of Quantities Extractor
A stateful agent system for extracting Bill of Quantities (BOQ) from tender documents and enabling document chat using LangGraph, LangChain, and Google Gemini LLM.
๐๏ธ Architecture
BOQTenders/
โโโ config/
โ โโโ settings.py # Pydantic settings with all configurable parameters
โโโ core/
โ โโโ agent.py # LangGraph-based agent for workflow orchestration
โ โโโ pdf_extractor.py # PDF text extraction via HuggingFace API
โ โโโ embeddings.py # Text chunking and FAISS vector store
โ โโโ llm.py # Google Gemini LLM client wrapper
โ โโโ rag_chain.py # RAG chain builder for document Q&A
โโโ services/
โ โโโ boq_extractor.py # BOQ extraction service with iterative consistency
โ โโโ consistency.py # Consistency checking service
โ โโโ mongo_store.py # MongoDB event logging
โ โโโ s3_utils.py # AWS S3 file storage
โโโ api/
โ โโโ routes.py # FastAPI routes for /get_boq and /chat
โ โโโ schemas.py # Pydantic request/response models
โโโ prompts/
โ โโโ get_prompts.py # Prompt loader
โ โโโ templates.yaml # LLM prompt templates
โโโ app.py # FastAPI entry point
โโโ streamlit_app.py # Streamlit UI entry point
โโโ Dockerfile # Docker configuration
โโโ docker-compose.yml # Docker Compose configuration
โโโ requirements.txt # Python dependenciesโจ Features
- ๐ PDF Processing: Extract text from tender documents using HuggingFace API
- ๐ BOQ Extraction: Automatically identify and extract BOQ items with:
- Item codes, descriptions, units, quantities
- Unit prices, total amounts
- Confidence scores for each item
- Source page references
- ๐ Consistency Checking: Iterative extraction with multiple runs for accuracy
- ๐ฌ Document Chat: Ask questions about processed documents using RAG
- ๐๏ธ Stateful Agent: LangGraph workflow for one-time extraction + multiple chats
- ๐ Logging & Storage: MongoDB event logging and S3 file storage
- ๐ Web UI: Streamlit interface for easy document upload and interaction
- ๐ API: FastAPI backend for programmatic access
Observability App โ OpenTelemetry โ OTEL Collector โ (Tempo, Prometheus, Loki) โ Grafana dashboards
Frontend Integration Use iframe embedding to show Grafana dashboards directly in your UI. See monitoring_api.py for iframe code generation.
๐ Quick Start
Prerequisites
- Python 3.8+
- Google Gemini API key
- MongoDB (optional, for logging)
- AWS S3 (optional, for file storage)
Installation
- Clone the repository:
git clone <repository-url>
cd BOQTenders- Create virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.env:
GOOGLE_API_KEY=your_gemini_api_key
HF_API_TOKEN=your_huggingface_token
LOG_LEVEL=DEBUG
# Optional: MongoDB and S3 configsUsage
Streamlit UI
streamlit run streamlit_app.py- Upload PDF, enter API key, process document for BOQ extraction.
- Chat with the document using the same API key.
FastAPI Backend
uvicorn app:app --reloadAPI Endpoints
POST /get_boq: Extract BOQ from uploaded PDFPOST /chat: Chat with processed document
๐ API Documentation
Extract BOQ
curl -X POST "http://localhost:8000/get_boq" \
-H "Content-Type: application/json" \
-d '{
"file": "base64_encoded_pdf",
"api_key": "your_api_key",
"runs": 2,
"boq_mode": ["default"]
}'Chat with Document
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"process_id": "session_id",
"question": "What is the total quantity?",
"api_key": "your_api_key"
}'๐ ๏ธ Development
Project Structure
core/agent.py: Main LangGraph agent with simplified workflowapi/routes.py: FastAPI endpoints using agentstreamlit_app.py: Web UI with session managementservices/: Business logic for extraction, consistency, storage
Key Components
- Agent Workflow: Linear extraction graph + direct chat calls
- State Management: AgentState TypedDict for workflow state
- Error Handling: Graceful failures with logging
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
