How ramkitcs/precisionfarming-1 works
Project Type and Purpose
• This is a precision-farming “intelligent recommendation engine” written in Python, combining a lightweight Streamlit UI with a LangChain/LangGraph–based RAG (Retrieval-Augmented Generation) core. It ingests user data (location, soil, images), calls domain-specific tools (weather API, vector store, web search, image classifiers), and stitches together an actionable plan via an LLM (OpenAI).
File Structure Analysis
• Top-level scripts:
• StreamLitApp.py – the frontend/UI layer
• PrecisionFarming.py, RetrievalGraph.py, AgentTools.py, CropVectorStore.py – core engine and tool definitions
• Models folder: pre-trained TensorFlow CNNs for insect and leaf classification
• Guides/ folder: PDF crop guides used as vector-store sources
• helper_functions.py & notebooks: ML training and data-prep artifacts
• requirements.txt, .gitignore – environment and deployment hints
Key Architectural Components
a. Frontend (Streamlit UI)
b. Orchestrator (LangGraph agentic workflow in PrecisionFarming.py)
c. Tools layer:
• Weather tool (get_weather_data → external WeatherAPI)
• PH calculators (decrease_ph, increase_ph)
• Water calculator (calculate_water_needed)
• Retrieval tools (get_crop_info, tackle_insect, tackle_disease) → vector store + web search (Tivaly)
• Image classifiers (TensorFlow CNNs)
d. Retrieval Graph (RetrievalGraph.py): well-defined nodes for multi-query retrieval, relevance filtering (TruLens), web search, response grounding (Upstage), query rewriting
e. LLM Layer (OpenAI calls) – final narrative generation
f. Data stores:
• Vector database of chunked PDF guides
• Possibly local file store for model artifacts
Component Interactions and Data Flow
• User inputs (UI) → REST/Direct call into the orchestrator
• Orchestrator analyzes input, invokes Tools in parallel or sequence:
• Weather → returns forecast & irrigation plan
• Soil PH/Water tools → numeric calculations
• CNN classifiers → insect/disease predictions
• Retrieval tools → fetch guidance from vector store or web
• RetrievalGraph may be invoked under the hood by specific tools
• All partial results feed back into the LLM, which assembles the final actionable plan
• Output → UI renders markdown response
Architectural Patterns & Principles
• Agentic orchestration with LangGraph for dynamic tool-calling
• RAG pattern for grounded retrieval + fallback web search
• Separation of concerns: UI (Streamlit) vs. orchestrator vs. tools vs. data/model stores
• Modular “@tool” annotations for easy extensibility
Detailing and Labeling
• Edges with function names or tool calls (e.g., “get_weather_data()”)
• Conditional or fallback paths in the Retrieval Graph (e.g., “if no vector hits → web search”)
• Feedback loops (e.g., relevance filter back into retrieval)
Final Recommendations
• Be exhaustive but clear: break the system into its logical sub-components
• Both the high-level workflow (UI → Engine → Output) and the internal branching for RAG, classification, and calculations
• How the LangGraph agent chooses between tools to meet the prompt