A prototype interactive estimation system using FastAPI, Langgraph, and Streamlit. This system guides users through a conversational flow to gather information for a service (e.g., roofing) and provides a structured estimate.
- Conversational Flow: Natural language conversation to gather project requirements
- Image Upload Support: Users can upload images related to their projects
- Smart Information Extraction: Uses AI to extract relevant information from user messages
- Dynamic Questioning: Adapts questions based on missing information
- Configurable Estimation Logic: Estimation calculations based on a flexible configuration
- Real-time Feedback: Updates the estimate as more information is provided
Windows:
# Run the PowerShell script
.\run.ps1macOS/Linux:
# Make the script executable
chmod +x run.sh
# Run the script
./run.sh- Clone the repository and navigate to the project directory
- Create and activate a virtual environment
- Install dependencies:
pip install -e . - Set up your environment variables (copy
.env.exampleto.envand add your OpenAI API key) - Run the application:
python run.py
docker-compose up- Installation Guide - Detailed setup instructions
- User Guide - How to use the system
- Architecture - System design and components
The system is built using a modern stack:
- Backend: FastAPI, Pydantic, Langchain, Langgraph, Uvicorn
- Frontend: Streamlit
- State Management: In-memory dictionary (for prototype simplicity)
- Language Model: OpenAI GPT-4o (via Langchain)
-
Input Handler (FastAPI & Streamlit):
- Accept text input and image uploads from users
- Manages session state and communication between frontend and backend
-
Conversation Manager (FastAPI & Langgraph):
- Maintains conversation state for each user session
- Uses Langgraph to define and manage the conversation flow
- Extracts information from user inputs
- Generates appropriate responses and questions
-
Estimation Logic (Python):
- Calculates estimates based on the provided configuration
- Supports various parameters (materials, regions, timelines, etc.)
- Generates a structured output with cost breakdown
interactive-estimation-system/
βββ backend/ # FastAPI backend
β βββ app/ # Application code
β β βββ __init__.py
β β βββ main.py # FastAPI app, endpoints
β β βββ models.py # Pydantic models
β β βββ graph.py # Langgraph definition
β β βββ estimator.py # Estimation calculation logic
β β βββ config.py # Load estimation config, API keys
β β βββ utils.py # Helper functions
β βββ requirements.txt # Backend dependencies
βββ frontend/ # Streamlit frontend
β βββ app.py # Streamlit application
β βββ requirements.txt # Frontend dependencies
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker build instructions
βββ setup.py # Package installation
βββ run.py # Script to run both servers
βββ run.ps1 # PowerShell script for Windows
βββ run.sh # Bash script for Unix/Linux
βββ .env.example # Example environment variables
βββ .gitignore # Git ignore file
βββ ARCHITECTURE.md # System architecture details
βββ INSTALL.md # Installation instructions
βββ USER_GUIDE.md # User documentation
βββ README.md # Project documentation
# Install test dependencies
pip install -e ".[test]"
# Run tests
pytestTo add new service types:
- Update the
config.jsonfile with the new service configuration - Add appropriate question templates in
utils.py - Update the information extraction schema in
graph.pyif needed
This prototype has several limitations that could be addressed in future versions:
- State Management: Currently uses in-memory storage, which is not persistent
- Error Handling: Basic error handling implemented
- Service Types: Currently focused on roofing; could be expanded
Potential enhancements:
- Persistent Storage: Add a database for session storage
- Real Image Analysis: Integrate computer vision to extract information from images
- Multiple Service Types: Expand to support various service types
- User Authentication: Add user accounts and authentication
- Enhanced UI: More interactive and responsive frontend
A few notable issues have been fixed in this version:
-
Recursion Limit Error: Fixed by using
ainvoke()instead ofinvoke()with a higher recursion limit. -
Infinite Recursion Loop: The graph was transitioning back to
input_processorwithout waiting for new user input. Fixed by modifying the graph to end after generating a response. -
Langgraph Return Type: Fixed the issue where Langgraph returns
AddableValuesDictinstead of aGraphStateobject. This is now properly converted usingGraphState(**result). -
Pydantic Warnings: Added filters to suppress PydanticSchemaJson warnings.
- Shakil Mosharrof
- Github Copilot
- Windsurf IDE
- OpenAI for the GPT models
- Langchain and Langgraph for the conversation flow management
- FastAPI and Streamlit for the application framework
