💡 Inspiration

Agriculture is the backbone of global food security, yet most farmers are paralyzed by fragmented data silosjuggling weather apps, manual soil tests, and disconnected hardware. I realized that simply putting a generic chatbot wrapper around an LLM wouldn't solve this. Real, operational farming requires an autonomous, context-driven AI agent that can seamlessly retrieve precise domain knowledge, parse real-time telemetry, and actually execute multi-step physical tasks.

I was inspired to build TerraLive: a comprehensive AI Agronomist. I didn't just want an AI that guesses what might be wrong; I wanted a proactive agent that actively queries Google Cloud for planetary-scale satellite data, cross-references local agronomy databases using lightning-fast Elastic Vector Search, and autonomously actuates IoT irrigation systems. I wanted to build a true "tool-driven agent" that orchestrates the entire farm ecosystem from the cloud to the soil.

⚙️ What it does

TerraLive is a multi-step, Elastic-powered AI agent designed for large-scale precision agriculture. Operating through a sleek, multimodal dashboard, the agent functions as a 24/7 autonomous farm manager, performing a complete operational loop:

  • Multimodal User Interaction: Farmers can interact with the agent natively via real-time voice, text, or by streaming live camera frames of their crops for instant visual diagnosis.
  • Real-Time Context Ingestion (Google Cloud & APIs): The agent constantly monitors edge telemetry (soil moisture, nitrogen) and dynamically pulls live Sentinel-2 satellite health scores (NDVI) via the Google Earth Engine API, combined with Open-Meteo 7-day weather forecasting.
  • The Elastic Brain (RAG & Telemetry Analytics): This is the agent's true core. Instead of relying on generic LLM knowledge, TerraLive uses Elasticsearch Serverless as its retrieval engine. It leverages ES|QL to aggregate and analyze unstructured IoT telemetry on the fly, and uses Elastic Vector Search (k-NN) to query hundreds of vectorized agricultural manuals for highly specific disease and treatment protocols.
  • Proactive Community Threat Radar: When the agent visually identifies an anomaly (e.g., Coffee Berry Disease), it uses custom Haversine algorithms to push a geospatial "Community Radar" threat warning to neighboring farms within a specific radius.
  • Financial Impact & Autonomous IoT Actuation: TerraLive doesn't just warn; it calculates the exact financial "Value at Risk" in the local currency, determines exact fertilizer/water deficits, securely logs the farm's state in TiDB Serverless, and autonomously triggers physical IoT infrastructure (e.g., activating Sector A's main pump).
  • Secure Action Auditing & Record-Keeping: Every agent action, system log, and user session is securely managed, scheduled, and synchronized via Firebase, ensuring the farmer has a perfect, real-time audit trail of what the AI decided to do and why.

🛠️ How I built it

I built TerraLive from the ground up as a solo developer, focusing on a robust backend architecture that could support a multi-tool agent running at low latency:

  • The Agent Reasoning Engine: I utilized the Gemini 2.0 Multimodal API as the primary reasoning engine, granting it access to a suite of distinct server-side tools to interact with the physical world.
  • Retrieval & State (The Elastic Core): I integrated Elasticsearch Serverless to act as the agent's memory and knowledge base. Vector search handles the semantic retrieval of complex agronomic protocols, while ES|QL handles the rapid querying of time-series sensor data.
  • Backend & Relational Data: Built with Python and FastAPI, handling complex WebSockets for the agent's live audio/vision streams. I used TiDB (Serverless MySQL) for transactional relational data (IoT digital twins, user state, farm boundaries).
  • Cloud & Auth: Google Cloud Platform hosts the core service accounts and Earth Engine integrations, while Firebase handles secure multi-tenant authentication and real-time Action Logging.
  • Frontend: A vanilla HTML/JS and CSS glassmorphic UI, featuring Leaflet maps with dynamic geospatial overlays and Chart.js for telemetry visualization.

🚧 Challenges I ran into

Building a tool-driven agent that executes real-world tasks is vastly different from building a standard chatbot. My biggest challenge was orchestration: ensuring the agent reliably fetched context before attempting to trigger an action or write to the database.

Initially, the agent struggled with hallucinating treatment volumes and misinterpreting sensor drops. I solved this by strictly grounding it in Elasticsearch. I built a multi-step pipeline where the agent is strictly forced to query the Elastic index for the correct protocol and run it through a backend calculator tool before it is allowed to respond to the farmer or actuate the TiDB-linked IoT valves. Handling asynchronous WebSocket streams alongside Firebase auth token validation also required significant state-management engineering.

🏆 Accomplishments that I'm proud of

I am incredibly proud of achieving a true "closed-loop" agent architecture. TerraLive goes far beyond passive monitoring. When the agent uses its vision tool to spot a disease, it logs the GPS coordinates, alerts neighboring farms, queries Elasticsearch for the exact Copper Fungicide protocol, calculates the financial impact, securely logs the event in Firebase, and actively schedules the IoT spray.

Seeing the UI dynamically update its interactive map, action logs, and IoT hardware switches autonomously—all orchestrated by the agent's backend reasoning is magical.

🧠 What I learned

This project completely reshaped my understanding of agentic AI. I learned that an agent is only as good as the tools and the retrieval architecture backing it. Elasticsearch proved to be the missing link for me—I learned how to combine the semantic understanding of Vector Search (for reading manuals) with the rigid, lightning-fast data querying of ES|QL (for reading sensor logs) to give the LLM perfect, unified context. I also deepened my knowledge of connecting serverless databases like TiDB with real-time Firebase listeners via Python WebSockets.

🚀 What's next for TerraLive

This hackathon was just the beginning. The immediate next steps for TerraLive include:

  • Full Cloud Deployment: Moving the FastAPI orchestrator from a local environment to a fully scalable, containerized architecture using Google Cloud Run to handle global farm traffic with zero downtime.
  • Expanding the Elastic Index: Ingesting a massive, global dataset of crop varieties, soil profiles, and regional climate strategies into Elasticsearch to make the agent viable and highly accurate in any country or biome.
  • Hardware Integration at Scale: Scaling our IoT edge integrations using robust MQTT protocols to allow the agent to directly command enterprise-grade agricultural hardware (drone dispatch systems, industrial pivot iterators) across thousands of acres.
  • Multi-Agent Swarm Architecture: Evolving the system into a collaborative multi-agent framework: one sub-agent dedicated solely to Elastic data analytics, another acting as a predictive financial advisor monitoring market prices, and a master orchestration agent that communicates directly with the farmer.

Built With

Share this project:

Updates