demeter

Autonomous Hydroponic Intelligence
commit 5e24d401bc13a699fdcb5f3a80e0ed016d803846
parent 724604d76ee3783f075310c7aeced5c2b093d51d
Author: maydayv7 <maydayv7@gmail.com>
Date:   Thu, 26 Mar 2026 19:35:30 +0530

Update README

Diffstat:
Dagent/Qdrant/Search.py | 0
Dassets/screenshots/agent_control.png | 0
Dassets/screenshots/demeter_dashboard.png | 0
Aassets/screenshots/landing_page.png | 0
Dassets/screenshots/system_overview.png | 0
Mbackend/server/functions.py | 2+-
Mfrontend/src/utils/translations.js | 2+-
Mreadme.md | 617+++++++++++++++++++++++++++++++++++--------------------------------------------
Mrequirements.txt | 83+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Dsimulator/requirements.txt | 10----------
10 files changed, 324 insertions(+), 390 deletions(-)

diff --git a/agent/Qdrant/Search.py b/agent/Qdrant/Search.py diff --git a/assets/screenshots/agent_control.png b/assets/screenshots/agent_control.png Binary files differ. diff --git a/assets/screenshots/demeter_dashboard.png b/assets/screenshots/demeter_dashboard.png Binary files differ. diff --git a/assets/screenshots/landing_page.png b/assets/screenshots/landing_page.png Binary files differ. diff --git a/assets/screenshots/system_overview.png b/assets/screenshots/system_overview.png Binary files differ. diff --git a/backend/server/functions.py b/backend/server/functions.py @@ -751,7 +751,7 @@ async def process_similar_crops(crop_id: str, crop_name: str, payload_json: str) ] ) - search_results = client.search( + search_results = client.query_points( collection_name=COLLECTION_NAME, query_vector=query_vector, query_filter=exclude_filter, diff --git a/frontend/src/utils/translations.js b/frontend/src/utils/translations.js @@ -12,7 +12,7 @@ const en = { nav_crops_need_attention: "{n} crop{s} need attention", nav_all_clear: "All clear", nav_harvest_ready: "๐ŸŒพ {n} ready to harvest", - sidebar_agri_ai: "AGRIยทAIยทv2", + sidebar_agri_ai: "AGRIยทAIยทv4", sidebar_connecting: "CONNECTINGโ€ฆ", sidebar_farm_online: "FARM ONLINE", sidebar_no_data: "NO DATA", diff --git a/readme.md b/readme.md @@ -1,229 +1,329 @@ -# Demeter: Autonomous Hydroponic Intelligence ๐ŸŒฟ๐Ÿค– +# Demeter - Autonomous Hydroponic Intelligence -<a href="https://drive.google.com/file/d/1VAN31mXPaQ7r4Fm8dpzjhgGeeQwvlH-Z/view?usp=drive_link"> - <img src="https://img.shields.io/badge/Demeter-Hydroponic_AI-4CAF50?style=for-the-badge&logo=robot&logoColor=white" alt="Demeter Logo"> -</a> +> _"The farm thinks for itself."_ -<div align="center"> +Demeter is a fully autonomous, multi-agent AI system for precision hydroponic farm management. +It combines reinforcement learning, computer vision, LLM-based reasoning, vector memory, and a physics-based digital twin to monitor, analyze, and act on crop conditions - **24/7, without human intervention.** -**Industrial-grade Multi-Agent System for autonomous hydroponic farming through AI-driven reasoning** +Built for the **Microsoft AI Unlocked - AI for India** hackathon, Demeter addresses food security and precision agriculture challenges in the Indian context, with full Hindi language support and a design philosophy accessible to rural operators. -[๐Ÿ“– Documentation](https://drive.google.com/file/d/1VAN31mXPaQ7r4Fm8dpzjhgGeeQwvlH-Z/view?usp=drive_link) โ€ข [๐Ÿš€ Quick Start](#-quick-start) โ€ข [๐Ÿ”ง API Reference](#-api-reference) +--- + +## Screenshots -</div> +![Landing Page](./assets/screenshots/landing_page.png) -<div align="center"> +--- -| ![System Overview](assets/screenshots/system_overview.png) | ![Agent Control](assets/screenshots/agent_control.png) | ![Console Log](assets/screenshots/console_log.png) | -| :--------------------------------------------------------: | :----------------------------------------------------: | :------------------------------------------------: | -| **System Overview**<br/>Real-time monitoring dashboard | **Agent Control**<br/>Multi-agent orchestration | **Console Log**<br/>AI agent decision logs | +## Key Features -</div> +### Multi-Agent System (MAS) ---- +- **7 specialized AI agents** collaborating in a structured pipeline +- **Contextual Bandit (MARL)** for cycle-level strategic goal selection based on historical rewards +- **LangGraph state machines** for each expert agent with tool-use and retry loops +- **Supervisor Agent** that synthesizes conflicting expert plans and enforces safety constraints -## ๐ŸŒŸ Overview +### AI & Machine Learning -**Demeter** is a revolutionary Multi-Agent System (MAS) that transforms hydroponic farming through intelligent automation. Unlike traditional rule-based systems that react to thresholds, Demeter employs a cognitive architecture that **perceives, reasons, and acts** like an expert grower. +- **Azure OpenAI (GPT-4.1)** powering all LLM-based reasoning agents +- **Azure Custom Vision** for real-time plant disease and pest detection +- **CLIP (ViT-B/32)** for plant image encoding into the FMU vector +- **Custom Contextual Bandit** (LinGreedy) for strategic action selection +- **RAG pipeline** with FastEmbed + Qdrant for domain knowledge retrieval -The system combines **Long-Term Memory**, **Computer Vision**, and **Reinforcement Learning** to optimize crop health in real-time, creating a truly autonomous farming experience. +### Memory & Storage -<div align="center"> - <img src="assets/screenshots/demeter_dashboard.png" alt="Demeter Dashboard" width="800"/> - <p><em>Demeter Web Dashboard - Real-time monitoring and control interface</em></p> -</div> +- **Qdrant Vector DB** - dual-collection architecture: + - `Crop_States` - FMU snapshots (image + sensor fused vectors) + - `Knowledge_Base` - agronomic research documents (RAG) + - `Plant_Biographies_HF` - long-term per-crop memory (via Mem0) +- **Mem0** - semantic plant biography system backed by Azure OpenAI +- **Node.js + MongoDB** - structured crop metadata and event logs -### ๐ŸŽฏ Key Capabilities +### Physics Simulator -- **๐Ÿง  Cognitive Decision Making**: AI agents that reason like human experts -- **๐Ÿ” Real-time Disease Detection**: Azure Custom Vision-powered visual diagnosis -- **๐Ÿ“š Scientific Knowledge Base**: RAG-enabled agricultural research integration -- **๐ŸŽฎ Adaptive Learning**: Reinforcement learning that improves over time -- **๐ŸŒ Live Data Integration**: Autonomous web search for current conditions -- **โšก Predictive Modeling**: Digital twin simulation before actions -- **๐Ÿ”’ Safety-First Design**: Multi-layer validation prevents harmful actions +- **Digital Twin** with a hybrid physics + neural residual model +- Simulates pH, EC, water temp, air temp, humidity, VPD, and biomass +- Exposes REST API consumed by both the agent loop and frontend +- Syncs state to **Azure Digital Twins** after every action --- -## ๐Ÿ—๏ธ System Architecture +## Tech Stack + +| Layer | Technology | +| ----------------------- | ---------------------------------------------------- | +| **LLM** | Azure OpenAI GPT-4.1 | +| **Agent Orchestration** | LangGraph, LangChain | +| **Vision** | Azure Custom Vision, CLIP ViT-B/32 (OpenAI) | +| **Vector DB** | Qdrant | +| **Semantic Memory** | Mem0 | +| **Embeddings** | FastEmbed (BAAI/bge-small-en-v1.5), all-MiniLM-L6-v2 | +| **Digital Twin** | Azure Digital Twins + custom physics sim | +| **Backend (Python)** | FastAPI, Uvicorn | +| **Backend (Node)** | Express.js, MongoDB | +| **Frontend** | React 19, React Router v7, Recharts, Tailwind CSS v3 | +| **Physics** | PyTorch (ResidualPhysicsNet), NumPy | +| **RL** | Custom Contextual Bandit (LinGreedy) | -Demeter operates on a **Hierarchical Control Loop** powered by **LangGraph**, featuring specialized agents that collaborate to maintain optimal growing conditions: +--- -<div align="center"> - <img src="assets/architecture.png" alt="Demeter System Architecture" width="800"/> - <p><em>Demeter Agent Hierarchy - Multi-agent cognitive architecture</em></p> -</div> +## Architecture -### ๐Ÿค– Agent Roles +![Architecture](./assets/architecture.png) -| Agent | Role | Technology | Purpose | -| --------------- | ------------- | -------------------- | --------------------------------------------- | -| **Supervisor** | Executive | Contextual Bandit RL | Strategic decision making & safety validation | -| **Researcher** | Scholar | RAG + Web Search | Scientific consultation & live data retrieval | -| **Judge** | Auditor | CV + Analytics | Performance evaluation & RL training | -| **Atmospheric** | Specialist | Physics Engine | VPD, CO2, light optimization | -| **Water** | Specialist | Chemistry Engine | pH, EC, nutrient balancing | -| **Doctor** | Diagnostician | Azure Custom Vision | Disease detection & visual analysis | -| **Historian** | Memory | Mem0 + Qdrant | Long-term plant biography & context | +### The Farm Management Unit (FMU) ---- +The FMU is the core data structure of Demeter. +It is a **fused multimodal vector** created by the Sentinel system at the start of every cycle: -## โœจ Key Features +``` +Image (512ร—512 plant photo) + โ†“ CLIP ViT-B/32 + [512-dim visual embedding] + + +Sensor Window (pH, EC, temp, humidity, VPD, biomass, ...) + โ†“ SensorEncoder (LSTM + linear projection) + [7-dim sensor embedding] + = +FMU Vector [519-dim] โ†โ†’ stored in Qdrant with full metadata payload +``` -### โšก Self-Correcting Reasoning +The FMU is stored in Qdrant and becomes the **memory of the farm** - every past state is retrievable by similarity search. -- **Digital Twin Simulation**: Predicts action consequences before execution, powered by Azure Digital Twin -- **Safety Interlocks**: Prevents harmful actions through multi-layer validation -- **Rollback Capabilities**: Can reverse unsafe decisions +--- -### ๐Ÿ” RAG-Powered Knowledge Base +### The 7-Agent Pipeline -- **Scientific Literature**: Indexes agricultural research papers and best practices -- **Contextual Retrieval**: Retrieves relevant information for current conditions -- **Hallucination Prevention**: All decisions grounded in verified sources +Each autonomous cycle follows this sequence: -### ๐ŸŽฏ Reinforcement Learning Optimization +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ DEMETER AGENT CYCLE โ”‚ +โ”‚ โ”‚ +โ”‚ 1. FetchingAgent โ”‚ +โ”‚ โ””โ”€ Polls simulator/ADT โ†’ builds FMU โ†’ stores in Qdrant โ”‚ +โ”‚ โ”‚ +โ”‚ 2. JudgeAgent (LangGraph) โ”‚ +โ”‚ โ””โ”€ Retrieves N-1 FMU โ†’ runs Azure CV (visual forensics) โ”‚ +โ”‚ โ””โ”€ Queries FarmMemory (Mem0) โ†’ deliberates via LLM โ”‚ +โ”‚ โ””โ”€ Files reward score โ†’ trains Bandit โ”‚ +โ”‚ โ”‚ +โ”‚ 3. SupervisorAgent โ†’ ContextualBandit โ”‚ +โ”‚ โ””โ”€ Encodes current FMU as context vector (519-dim) โ”‚ +โ”‚ โ””โ”€ Bandit selects 1 of 15 strategies (LinGreedy) โ”‚ +โ”‚ โ””โ”€ Strategy instruction passed to expert agents โ”‚ +โ”‚ โ”‚ +โ”‚ 4. ResearcherAgent โ”‚ +โ”‚ โ””โ”€ Queries Knowledge_Base (RAG) for crop-specific data โ”‚ +โ”‚ โ”‚ +โ”‚ 5. AtmosphericAgent (LangGraph) โ”‚ +โ”‚ โ””โ”€ Tools: ask_rag, web_search, calculate_vpd, diagnose_plantโ”‚ +โ”‚ โ””โ”€ Generates climate action plan (temp/humidity/CO2/light) โ”‚ +โ”‚ โ””โ”€ Simulates plan โ†’ retry loop if unsafe โ”‚ +โ”‚ โ”‚ +โ”‚ 6. WaterAgent (LangGraph) โ”‚ +โ”‚ โ””โ”€ Tools: ask_rag, web_search, calculate_vpd, diagnose_plantโ”‚ +โ”‚ โ””โ”€ Generates nutrient plan (pH dosing, EC adjustment) โ”‚ +โ”‚ โ””โ”€ Simulates plan โ†’ retry loop if unsafe โ”‚ +โ”‚ โ”‚ +โ”‚ 7. SupervisorAgent โ†’ synthesize_plan โ”‚ +โ”‚ โ””โ”€ Merges atmospheric + water plans โ”‚ +โ”‚ โ””โ”€ Detects conflicts, enforces safety bounds โ”‚ +โ”‚ โ””โ”€ Dispatches final FarmAction to Simulator/ADT โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` -- **Contextual Bandit Algorithm**: Learns optimal strategies over time -- **Adaptive Decision Making**: Improves performance based on outcomes -- **Strategy Evolution**: Discovers better approaches through trial and feedback +### The 15-Strategy MARL Bandit -### ๐Ÿ‘๏ธ Advanced Computer Vision +The Contextual Bandit (`agent/Marl/bandit.py`) is a **LinGreedy** (pure-exploitation) contextual bandit that selects from 15 farm management strategies: -- **Real-time Disease Detection**: Identifies pathogens before symptoms appear -- **Growth Stage Analysis**: Monitors plant development and health indicators -- **Automated Documentation**: Creates visual records of plant conditions +| Category | Strategies | +| ------------ | ----------------------------------------------------------------------------------------------- | +| ๐ŸŸข Passive | MAINTAIN_CURRENT, CALIBRATE_SENSORS | +| ๐Ÿ’ง Nutrients | AGGRESSIVE_PH_DOWN/UP, GENTLE_PH_BALANCING, INCREASE_EC_VEG/BLOOM, LOWER_EC_FLUSH, CALMAG_BOOST | +| ๐ŸŒค๏ธ Climate | RAISE_TEMP_HUMIDITY, LOWER_TEMP_HUMIDITY, MAX_AIR_CIRCULATION | +| ๐Ÿš‘ Disease | FUNGAL_TREATMENT, PEST_ISOLATION, PRUNE_NECROTIC_LEAVES | -### ๐ŸŒ Autonomous Intelligence +The bandit uses the **519-dim FMU vector as its context**, learns reward signals from the JudgeAgent, and persists its model weights to disk (`model_bandit_greedy.pkl`). -- **Live Web Search**: Fetches current weather, market data, and research -- **Dynamic Knowledge Updates**: Integrates new information without redeployment -- **Environmental Adaptation**: Adjusts to local conditions and climate changes +### The JudgeAgent - Closing the RL Loop ---- +The JudgeAgent is the reward signal generator. After each cycle, it: -## ๐Ÿ› ๏ธ Technology Stack +1. Retrieves the previous FMU (N-1) from Qdrant +2. Runs **Azure CV-based visual diagnosis** on the plant image +3. Queries **Mem0** for the crop's text biography +4. **Deliberates** via LLM: compares sensor delta, visual report, and history +5. Issues a reward score (โˆ’1.0 to +1.0) and outcome classification +6. **Updates Qdrant** payload and **writes to FarmMemory (Mem0)** +7. Returns training data โ†’ Bandit updates its weights online -### Backend (AI Brain) +### The Simulator - Physics + Neural Residual Digital Twin -```python -# Core Framework -- FastAPI 0.109+ # High-performance async API -- Python 3.11+ # Modern Python with performance optimizations +The simulator (`simulator/main.py`) is a **FastAPI server** running a `DigitalTwin` class: -# AI Orchestration -- LangChain 0.1+ # LLM orchestration framework -- LangGraph 0.0.26+ # Multi-agent workflow management +- **Hybrid physics model**: First-principles equations for pH, EC, VPD, biomass growth +- **Neural residual**: A small `ResidualPhysicsNet` (PyTorch MLP) that corrects physics approximations +- **State vector**: `[pH, EC, water_temp, air_temp, humidity, VPD, biomass]` +- **Image generation**: Outputs plant health images based on a bucket score (0โ€“100) +- **Azure Digital Twins sync**: Every action call pushes telemetry to the ADT twin (`HydrophonicTank`) +- **Dual endpoints**: `/simulation/state` (agent loop) and `/azure/state` (ADT read-back) -# AI Models -- Azure Custom Vision # Object detection for disease identification -- Llama-3.3-70b (Groq) # Primary LLM for reasoning -- OpenAI GPT-4o # Fallback LLM option -- CLIP (OpenAI) # Vision-language understanding +--- -# Data & Memory -- Azure Digital Twin # Digital farm simulation -- Qdrant # Vector database for RAG and embeddings -- Mem0 # Semantic long-term memory -- FastEmbed # Local embedding generation -``` +## Frontend -### Frontend (User Interface) +The frontend is a highly responsive React 19 SPA featuring bilingual support (English/เคนเคฟเคจเฅเคฆเฅ€) for accessibility in Indian agriculture, made to serve as a Proof-of-Concept. -```javascript -- React 19+ # Modern UI framework -- React Router 7+ # Client-side routing -- Tailwind CSS 3+ # Utility-first styling -- Recharts 3+ # Data visualization -- Lucide React # Icon library -``` +### Pages -### Infrastructure +| Page | Route | Description | +| ----------------- | --------------- | -------------------------------------------------------------------------------------------------- | +| Landing Page | `/` | Hero, live agent activity feed, feature cards, live stats | +| Dashboard | `/dashboard` | Crop card grid with health/maturity/stage filters and harvest banner | +| Crop Details | `/crop/:id` | Per-crop sensor charts, agent reasoning log, event timeline, actuator commands | +| Add Crop | `/add-crop` | Form to initialize a crop + live agent pipeline log with 6-phase progress tracker | +| Farm Intelligence | `/intelligence` | Natural-language RAG search against the agronomic knowledge base | +| Analytics | `/analytics` | Multi-chart analytics: pH/EC/temp traces, daily sequences, parameter health scores, per-crop table | +| Alerts | `/alerts` | Categorized alert system (CRITICAL/WARNING/INFO/HARVEST) with acknowledge workflow | +| Settings | `/settings` | Theme, language, farm name, notification prefs, onboarding | -- **Database**: Qdrant (Vector Search) -- **Deployment**: Docker containers -- **Monitoring**: Built-in logging and health checks -- **Security**: API key authentication and validation +--- + +## Project Structure + +``` +demeter/ +โ”œโ”€โ”€ agent/ +โ”‚ โ”œโ”€โ”€ main_agent.py # Orchestration loop (runs the 7-agent cycle) +โ”‚ โ”œโ”€โ”€ memory.py # FarmMemory class (Mem0 + Qdrant) +โ”‚ โ”œโ”€โ”€ Marl/ +โ”‚ โ”‚ โ”œโ”€โ”€ bandit.py # Contextual Bandit (LinGreedy, 15 arms) +โ”‚ โ”‚ โ”œโ”€โ”€ strategies.py # Strategy definitions +โ”‚ โ”‚ โ””โ”€โ”€ train-bandit.py # Offline training script +โ”‚ โ”œโ”€โ”€ Sentinel/ +โ”‚ โ”‚ โ”œโ”€โ”€ agent.py # FMUBuilder - creates fused vectors +โ”‚ โ”‚ โ”œโ”€โ”€ fmu.py # FMU dataclass +โ”‚ โ”‚ โ””โ”€โ”€ Encoders/ +โ”‚ โ”‚ โ”œโ”€โ”€ Vision.py # CLIP ViT-B/32 image encoder +โ”‚ โ”‚ โ””โ”€โ”€ TimeSeries.py # LSTM-based sensor encoder +โ”‚ โ”œโ”€โ”€ Qdrant/ +โ”‚ โ”‚ โ”œโ”€โ”€ Client.py # Qdrant client singleton +โ”‚ โ”‚ โ”œโ”€โ”€ Setup.py # Collection initialization +โ”‚ โ”‚ โ”œโ”€โ”€ Store.py # FMU storage helpers +โ”‚ โ”‚ โ””โ”€โ”€ Search.py # Similarity search helpers +โ”‚ โ”œโ”€โ”€ sub_agents/ +โ”‚ โ”‚ โ”œโ”€โ”€ base_agent.py # BaseReasoningAgent (Azure OpenAI client) +โ”‚ โ”‚ โ”œโ”€โ”€ fetching_agent.py # FetchingAgent - polls simulator, builds FMU +โ”‚ โ”‚ โ”œโ”€โ”€ judge_agent.py # JudgeAgent - reward evaluation (LangGraph) +โ”‚ โ”‚ โ”œโ”€โ”€ atmospheric_agent.py # AtmosphericAgent - climate planning (LangGraph) +โ”‚ โ”‚ โ”œโ”€โ”€ water_agent.py # WaterAgent - nutrient planning (LangGraph) +โ”‚ โ”‚ โ”œโ”€โ”€ Supervisor.py # SupervisorAgent - strategy + synthesis +โ”‚ โ”‚ โ”œโ”€โ”€ Researcher.py # ResearcherAgent - RAG knowledge retrieval +โ”‚ โ”‚ โ”œโ”€โ”€ Explainer.py # ExplainerAgent - chain-of-thought log generation +โ”‚ โ”‚ โ”œโ”€โ”€ Doctor.py # VisionAgent - plant disease detection (Azure Custom Vision) +โ”‚ โ”‚ โ””โ”€โ”€ water_and_atmospheric_dependencies/ +โ”‚ โ”‚ โ”œโ”€โ”€ state.py # LangGraph AgentState definition +โ”‚ โ”‚ โ”œโ”€โ”€ nodes.py # LangGraph node functions +โ”‚ โ”‚ โ”œโ”€โ”€ tools.py # LangChain tools (calculate_vpd, web_search) +โ”‚ โ”‚ โ”œโ”€โ”€ physics_engine.py# LLM-based plan safety simulator +โ”‚ โ”‚ โ””โ”€โ”€ retrieval.py # LangChain tools (ask_rag, diagnose_plant, ask_memory) +โ”‚ โ””โ”€โ”€ tools/ +โ”‚ โ”œโ”€โ”€ actuation.py # Actuator command builders +โ”‚ โ”œโ”€โ”€ db_tools.py # Database utility tools +โ”‚ โ”œโ”€โ”€ processing_tools.py # Sensor processing utilities +โ”‚ โ””โ”€โ”€ reset_memory.py # Memory reset utility +โ”‚ +โ”œโ”€โ”€ backend/ +โ”‚ โ”œโ”€โ”€ server/ +โ”‚ โ”‚ โ”œโ”€โ”€ main.py # FastAPI server (Python) - agent HTTP endpoints +โ”‚ โ”‚ โ”œโ”€โ”€ functions.py # Backend utility functions +โ”‚ โ”‚ โ”œโ”€โ”€ rag_brain.py # PDF ingestion pipeline for Knowledge Base +โ”‚ โ”‚ โ”œโ”€โ”€ create-index.py # Qdrant index setup script +โ”‚ โ”‚ โ””โ”€โ”€ reset-db.py # Database reset utility +โ”‚ โ””โ”€โ”€ node_server/ +โ”‚ โ”œโ”€โ”€ index.js # Express.js server - crop CRUD API +โ”‚ โ”œโ”€โ”€ routes/farmRoutes.js # Farm route definitions +โ”‚ โ”œโ”€โ”€ controllers/ # Farm controller logic +โ”‚ โ””โ”€โ”€ config/db.js # MongoDB connection +โ”‚ +โ”œโ”€โ”€ frontend/ +โ”‚ โ”œโ”€โ”€ src/ +โ”‚ โ”‚ โ”œโ”€โ”€ App.js # Router, providers, onboarding gate +โ”‚ โ”‚ โ”œโ”€โ”€ pages/ # All 8 page components +โ”‚ โ”‚ โ”œโ”€โ”€ components/ # Sidebar, AgentWidgets, Onboarding +โ”‚ โ”‚ โ”œโ”€โ”€ hooks/ # useFarmData, useSettings, useTranslation +โ”‚ โ”‚ โ”œโ”€โ”€ api/ # agentApi.js, farmApi.jsx +โ”‚ โ”‚ โ”œโ”€โ”€ utils/ # translations.js, dataUtils.js +โ”‚ โ”‚ โ””โ”€โ”€ data/mockData.js # Mock data for testing +โ”‚ โ””โ”€โ”€ tailwind.config.js +โ”‚ +โ”œโ”€โ”€ simulator/ +โ”‚ โ””โ”€โ”€ main.py # DigitalTwin + FastAPI server + Azure ADT sync +โ”‚ +โ”œโ”€โ”€ Knowledge_Base/ # Drop agronomic PDFs here for RAG ingestion +โ”œโ”€โ”€ requirements.txt +โ””โ”€โ”€ README.md +``` --- -## ๐Ÿš€ Quick Start +## Setup & Installation ### Prerequisites -Before installing Demeter, ensure you have: - -- **Python 3.10+** - [Download](https://www.python.org/downloads/) -- **Node.js 16+** - [Download](https://nodejs.org/) -- **Git** - [Download](https://git-scm.com/) -- **Docker Desktop** (for local Qdrant) OR [Qdrant Cloud account](https://cloud.qdrant.io/) +- Python 3.10+ +- Node.js 18+ +- A running [Qdrant](https://qdrant.tech/) instance (local Docker or Qdrant Cloud) +- Azure OpenAI resource with GPT-4.1 deployment +- (Optional) Azure Digital Twins instance -### 1. Clone and Setup +### 1. Clone & Install Python Dependencies ```bash -# Clone the repository git clone https://github.com/maydayv7/demeter.git cd demeter - -# Create virtual environment -python -m venv .venv -source .venv/bin/activate # Windows: .venv\Scripts\activate - -# Install Core Python dependencies -pip install -r requirements.txt - -# Install Simulator dependencies -cd simulator pip install -r requirements.txt -cd .. - -# Install Backend Node dependencies -cd backend/node_server -npm install -cd ../.. - -# Install Frontend dependencies -cd frontend -npm install -cd .. ``` -### 2. Environment Configuration +### 2. Configure Environment Variables -Create a **single** `.env` file in the **project root directory**. All components are configured to read from this top-level file automatically. +Create a `.env` file in the project root: ```env -# Database -QDRANT_URL=http://localhost:6333 -QDRANT_API_KEY=your_qdrant_key_here +# Azure OpenAI +AZURE_OPENAI_API_KEY=your_azure_openai_key +AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/ +AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4.1 +AZURE_OPENAI_API_VERSION=2024-12-01-preview -# LLM -GROQ_API_KEY=gsk_your_key_here +# Qdrant +QDRANT_URL=http://localhost:6333 +QDRANT_API_KEY=your_qdrant_api_key # Only needed for Qdrant Cloud + +# Azure Custom Vision +AZURE_API_KEY=your_azure_api_key +AZURE_ENDPOINT=your_azure_endpoint +AZURE_PROJECT_ID=your_azure_project_id +AZURE_PREDICTION_KEY=your_azure_prediction_key +AZURE_URL=your_azure_url +AZURE_ITERATION_NAME=DemeterDoctor +DATASET_FOLDER="train" # Simulator -SIMULATOR_PORT=8001 -SIMULATOR_ACTION_URL=http://localhost:8001/simulation/action SIMULATOR_STATE_URL=http://localhost:8001/simulation/state -ADT_URL=simulator.api.krc.digitaltwins.azure.net -AZURE_TENANT_ID=your_azure_tenant_id_here -AZURE_CLIENT_ID=your_service_principal_client_id_here -AZURE_CLIENT_SECRET=your_service_principal_client_secret_here +SIMULATOR_ACTION_URL=http://localhost:8001/simulation/action +SIMULATOR_PORT=8001 -# Node Backend -PORT=3001 +# Azure Digital Twins +ADT_URL=your-adt-instance.digitaltwins.azure.net -# React Frontend +# Frontend REACT_APP_AGENT_API_URL=http://localhost:8000 REACT_APP_FARM_API_URL=http://localhost:3001/api - -# Azure Services -AZURE_API_KEY=your_azure_key_here -AZURE_ENDPOINT=azure_endpoint_here -AZURE_PROJECT_ID=your_azure_project_id_here -DATASET_FOLDER="train" -AZURE_PREDICTION_KEY=your_azure_predict_key_here -AZURE_URL=your_azure_url_here -AZURE_ITERATION_NAME=DemeterDoctor +PORT=3001 ``` ### 3. Start Qdrant Database @@ -247,220 +347,53 @@ Run the following command from the root directory to create the required collect python backend/server/create-index.py ``` -### 5. Start the Simulator +### 5. Initialize the Knowledge Base (RAG) -Open a new terminal, activate the virtual environment, and run the Digital Twin Simulator from its directory: +Place agronomic PDFs in the `Knowledge_Base/` folder, then run: ```bash -cd simulator -python main.py +python backend/server/rag_brain.py ``` -### 6. Start the Agents - -Download [model_bandit_greedy.pkl](https://drive.google.com/file/d/1spuw3TogZRtP0fYZkYA2Kxz1-CiUzBDA/view?usp=drive_link) and [plant_disease_model.pt](https://drive.google.com/file/d/1NkdGt0CFS7tx4vttp8Tod8ksjDLib8dp/view?usp=drive_link) and place them under `agent/Marl` and `agent/model` respectively. +Otherwise, download [model_bandit_greedy.pkl](https://drive.google.com/file/d/1spuw3TogZRtP0fYZkYA2Kxz1-CiUzBDA/view?usp=drive_link) and place it inside the `agent/Marl` directory. -Open a new terminal, activate the virtual environment, and start the agent orchestrator from the agent directory: +### 6. Start the Simulator ```bash -cd agent -python main_agent.py +cd simulator +python main.py +# Runs on http://localhost:8001 ``` -### 7. Start the Backends +### 7. Start the Backend Servers -**Python API Server:** -Open a new terminal, activate the virtual environment, and start the FastAPI server from the backend directory: +Download [plant_disease_model.pt](https://drive.google.com/file/d/1NkdGt0CFS7tx4vttp8Tod8ksjDLib8dp/view?usp=drive_link) and place it inside the `agent/model` directory. ```bash +# Python FastAPI server cd backend/server -python main.py -``` +uvicorn main:app --reload --port 8000 -**Node.js Database Server:** -Open a new terminal and start the Express server for fetching from the memory database: - -```bash +# Node.js Express server cd backend/node_server -npm start +npm install && npm start ``` -### 8. Run the Frontend - -Open a new terminal, navigate to the frontend directory, and run the development server: +### 8. Start the Frontend ```bash cd frontend +npm install npm start +# Runs on http://localhost:3000 ``` -### 9. Access the Application - -- **Frontend**: http://localhost:3000 -- **API Documentation**: http://localhost:8000/docs -- **Health Check**: http://localhost:8000/health - -<div align="center"> - <img src="assets/screenshots/agent_control.png" alt="Agent Control Interface" width="700"/> - <p><em>Agent Control Dashboard - Monitor and interact with AI agents in real-time</em></p> -</div> - ---- - -## ๐Ÿ“ Project Structure - -``` -demeter/ -โ”œโ”€โ”€ agent/ # AI Agent System -โ”‚ โ”œโ”€โ”€ main_agent.py # Main orchestrator -โ”‚ โ”œโ”€โ”€ sub_agents/ # Specialized agents -โ”‚ โ”‚ โ”œโ”€โ”€ Supervisor.py # Executive decision maker -โ”‚ โ”‚ โ”œโ”€โ”€ Researcher.py # RAG-powered research -โ”‚ โ”‚ โ”œโ”€โ”€ judge_agent.py # Performance auditor -โ”‚ โ”‚ โ”œโ”€โ”€ atmospheric_agent.py # Climate control -โ”‚ โ”‚ โ”œโ”€โ”€ water_agent.py # Hydroponics management -โ”‚ โ”‚ โ””โ”€โ”€ Doctor.py # Disease diagnostician -โ”‚ โ”œโ”€โ”€ Qdrant/ # Vector database clients -โ”‚ โ”œโ”€โ”€ tools/ # Agent utilities -โ”‚ โ”œโ”€โ”€ memory.py # Long-term memory system -โ”‚ โ””โ”€โ”€ model/ # ML models -โ”œโ”€โ”€ backend/ # API Server -โ”‚ โ”œโ”€โ”€ server/ -โ”‚ โ”‚ โ”œโ”€โ”€ main.py # FastAPI application -โ”‚ โ”‚ โ”œโ”€โ”€ functions.py # Business logic -โ”‚ โ”‚ โ””โ”€โ”€ rag_brain.py # AI integration -โ”‚ โ””โ”€โ”€ node_server/ # Additional API endpoints -โ”œโ”€โ”€ frontend/ # React Application -โ”‚ โ”œโ”€โ”€ src/ -โ”‚ โ”‚ โ”œโ”€โ”€ components/ # UI components -โ”‚ โ”‚ โ”œโ”€โ”€ pages/ # Application pages -โ”‚ โ”‚ โ””โ”€โ”€ api/ # API integration -โ”‚ โ””โ”€โ”€ public/ # Static assets -โ”œโ”€โ”€ requirements.txt # Python dependencies -โ””โ”€โ”€ README.md # This file -``` - ---- - -## ๐Ÿ”ง API Reference - -### Core Endpoints - -| Method | Endpoint | Description | -| ------ | ------------------------ | -------------------- | -| `GET` | `/health` | System health check | -| `GET` | `/api/farms` | List all farms | -| `POST` | `/api/farms` | Create new farm | -| `GET` | `/api/farms/{id}` | Get farm details | -| `POST` | `/api/agents/action` | Trigger agent action | -| `GET` | `/api/memory/{plant_id}` | Get plant history | - -### Agent Control - -```bash -# Get current system status -curl http://localhost:8000/health - -# Trigger manual agent cycle -curl -X POST http://localhost:8000/api/agents/action \ - -H "Content-Type: application/json" \ - -d '{"action": "analyze", "farm_id": "farm_001"}' - -# Query plant memory -curl http://localhost:8000/api/memory/plant_123 -``` - -### WebSocket Real-time Updates - -```javascript -// Connect to real-time updates -const ws = new WebSocket("ws://localhost:8000/ws/farm-updates"); - -ws.onmessage = (event) => { - const data = JSON.parse(event.data); - console.log("Farm update:", data); -}; -``` - ---- - -## ๐Ÿ” Monitoring & Troubleshooting - -### Health Checks +### 9. Run the Agent Loop ```bash -# Check system health -curl http://localhost:8000/health - -# Check agent status -curl http://localhost:8000/api/agents/status - -# View logs -tail -f logs/demeter.log +python agent/main_agent.py ``` -### Common Issues - -**Q: Agents not responding** - -- Check Qdrant connection: `curl http://localhost:6333/health` -- Verify API keys in `.env` -- Ensure virtual environment is activated - -**Q: Memory not persisting** - -- Check Qdrant collections: Access Qdrant dashboard -- Verify embedding model is loaded -- Check disk space and permissions - -**Q: Vision analysis failing** - -- Check camera/image permissions -- Verify OpenCV installation - -**Q: Web search not working** - -- Validate SerpAPI key -- Check internet connectivity -- Review API quota limits - -### Performance Tuning - -```python -# Adjust agent cycle frequency -AGENT_CYCLE_INTERVAL = 300 # seconds - -# Configure memory limits -MAX_MEMORY_ENTRIES = 10000 - -# Set vision model confidence threshold -VISION_CONFIDENCE_THRESHOLD = 0.7 -``` - ---- - -## ๐Ÿ“Š Performance Metrics - -### System Benchmarks - -- **Decision Latency**: <2 seconds per cycle -- **Memory Retrieval**: <500ms average -- **Vision Analysis**: <1 second per image -- **RAG Query**: <300ms average -- **Uptime**: 99.9% target - -### Accuracy Metrics - -- **Disease Detection**: 94% accuracy (Azure CV fine-tuned) -- **Decision Quality**: 89% optimal actions (RL trained) -- **Safety Compliance**: 100% (validation enforced) - --- -<div align="center"> - **Made with โค๏ธ for the future of sustainable agriculture** - -[๐ŸŒŸ Star us on GitHub](https://github.com/maydayv7/demeter) โ€ข [๐Ÿ› Report a bug](https://github.com/maydayv7/demeter/issues) โ€ข [๐Ÿ’ก Request a feature](https://github.com/maydayv7/demeter/issues/new?template=feature_request.md) - -</div> diff --git a/requirements.txt b/requirements.txt @@ -1,39 +1,50 @@ -# --- Core Framework & Server --- -fastapi>=0.109.0 -uvicorn[standard]>=0.27.0 -python-multipart>=0.0.9 -python-dotenv>=1.0.0 -pydantic>=2.6.0 -requests>=2.31.0 - -# --- AI Orchestration (LangChain) --- -langchain>=0.1.0 -langchain-core>=0.1.10 -langchain-openai>=0.0.5 -langgraph>=0.0.26 -langchain-community>=0.0.10 - -# --- Database & Memory --- -qdrant-client>=1.7.0 -mem0ai>=0.0.12 -fastembed>=0.2.0 - -# --- Computer Vision & Machine Learning --- +# Core Framework & Server +fastapi>=0.115.0 +uvicorn[standard]>=0.30.0 +python-multipart>=0.0.12 +python-dotenv>=1.0.1 +pydantic>=2.9.0 +requests>=2.32.0 +httpx>=0.27.0 +aiofiles>=24.1.0 + +# AI Orchestration +langchain>=0.3.0 +langchain-core>=0.3.0 +langchain-openai>=0.2.0 +langgraph>=0.2.0 +langchain-community>=0.3.0 + +# Azure SDKs +openai>=1.50.0 +azure-identity>=1.19.0 +azure-digitaltwins-core>=1.2.0 + +# Vector Database & Memory +qdrant-client>=1.12.0 +mem0ai>=0.1.0 +fastembed>=0.4.0 + +# Computer Vision & Machine Learning numpy>=1.26.0 -torch>=2.2.0 -torchvision>=0.17.0 -opencv-python>=4.9.0.80 -Pillow>=10.2.0 - -# --- CLIP (OpenAI) --- -# Required for Sentinel/Vision Encoders -ftfy -regex -tqdm +torch>=2.3.0 +torchvision>=0.18.0 +opencv-python>=4.10.0 +Pillow>=10.4.0 +ultralytics>=8.2.0 + +# CLIP (OpenAI) +ftfy>=6.2.0 +regex>=2024.5.15 +tqdm>=4.66.0 git+https://github.com/openai/CLIP.git -# --- Utilities --- -aiofiles>=23.2.1 -httpx>=0.26.0 -sentence_transformers -openai-whisper +# RAG / Document Ingestion +pypdf>=4.3.0 +sentence-transformers>=3.0.0 + +# Speech +openai-whisper>=20231117 + +# Utilities +scipy>=1.13.0 diff --git a/simulator/requirements.txt b/simulator/requirements.txt @@ -1,10 +0,0 @@ -fastapi -uvicorn -pydantic -numpy -torch -Pillow -python-dotenv -azure-identity -azure-digitaltwins-core -openai