Inspiration

Agriculture remains one of the most climate-sensitive sectors in the world, especially across sub-Saharan Africa. In Nigeria, millions of smallholder farmers still depend heavily on predictable seasonal weather patterns for survival and crop productivity. However, accelerating climate change has rewritten these rules. Today, unpredictable dry spells, sudden intense downpours, and rapid shifts in microclimatic thresholds make traditional farming methods risky.

Many smallholders lack access to real-time micro-level parameters, forcing them to rely on regional, generalized forecasts or historical guesswork when deciding when to plant, irrigate, apply fertilizer, or spray for pests. Seeing these operational challenges firsthand, we were inspired to create AgriClimate AI Agent. I wanted to build something fundamentally different from a static dashboard or a basic Q&A chatbot: an autonomous, multi-step agent capable of acting as an on-call agronomist that actively plans, reasons, and executes context-driven safety workflows for vulnerable farms.

What it does

AgriClimate AI Agent is an end-to-end autonomous climate decision-support system designed to empower farmers with highly localized, actionable agricultural intelligence. Accessible via a modern web interface, the system provides several core modules:

Weather Engine: Scans live GPS coordinates or handles manual sector selection to connect to open meteorological streams, extracting parameters such as ambient temperature ($T$), relative humidity ($RH$), precipitation ($P$), and wind speeds, alongside seasonal trends and 7-day breakdowns. MCP-Enhanced Crop Advisory: Rather than immediately dumping live data into an LLM prompt, the core agent uses the Model Context Protocol (MCP) to query historical data first. It independently checks user preferences, past advisories, and historical disease patterns stored in MongoDB before synthesizing the information into native structured insights (DOs and DONTs ) across 9 localized and international languages, accompanied by automated text-to-speech engine playbacks. Disease Detection: A specialized predictive module that tracks real-time telemetry inputs against predefined crop epidemiological thresholds, warning farmers of environmental windows ideal for pest and fungus outbreaks. Alert System: Monitors live telemetry changes dynamically, serving instantaneous visual alerts for extreme weather thresholds (e.g., flash flood risks, severe heatwaves, or unseasonal droughts). Secure Auth Subsystem: Features full JSON Web Token (JWT) user authentication backed by a persistent MongoDB registry to give each user a personalized historical workspace.

How we built it

The platform is built on an robust, modern decoupled technical stack designed for ultra-low latency and scalable analytical workflows:

Frontend UI Node: Crafted using Vue.js 3 and Tailwind CSS to produce a hyper-focused responsive grid framework. Spatial visualizations are supported using Leaflet Maps, while climate trends are rendered beautifully through responsive ApexCharts instances.

  • Backend Orchestrator: Engineered as an asynchronous event-driven server environment running on Node.js and Express, utilizing tokenized JWT states to securely lock down REST API endpoints.
  • The Brain (AI Layer): Leverages Google Gemini to execute complex multi-step reasoning, utilizing structured formatting prompts and native linguistic translations.
  • The Superpower (Data Layer & Protocol): Built with MongoDB Atlas, accessed natively via the Model Context Protocol (MCP). Instead of using hardcoded database queries, the Gemini brain interacts natively with an official MongoDB MCP Server, dynamically executing tool schemas such as query_disease_outbreaks, analyze_telemetry_risk, get_active_alerts, and get_advisory_history.
  • Weather Streams: Grounded with hyperlocal weather metrics fetched from the Open-Meteo API.

Mathematical Foundations for Disease Risk Analysis

The agent evaluates the probability of disease outbreak ($P_{outbreak}$) using empirical weather index variables. For instance, fungal outbreaks are calculated as a factor of prolonged high relative humidity ($RH$) and optimal temperature ranges ($T_{opt}$):

$$P_{outbreak} = \frac{1}{1 + e^{-k \cdot (\int_{0}^{t} (RH(t) - RH_{threshold})\,dt \cdot f(T))}}$$

Where $k$ represents a crop-specific growth constant and $f(T)$ scales based on how close current ambient temperatures are to the pathogen's optimal breeding range ($T_{opt}$):

$$f(T) = \exp\left(-\left(\frac{T - T_{opt}}{\sigma}\right)^2\right)$$

The agent evaluates these integrals dynamically using data retrieved via the MCP database server before outputting risk levels to the farmer.

Challenges I ran into

Building a true autonomous agent on a tight timeline brought several strict technical hurdles:

  1. Transitioning from Dashboard to Autonomous Agent Architecture: Initially, the modules acted like standard web views where the frontend hardcoded database calls. Refactoring this to follow an MCP Server architecture required us to rewrite our integration logic. I had to expose MongoDB queries as tools so the Gemini model could plan its own multi-step data gathering loops.
  2. Browser Security & CORS Boundaries: Early iterations suffered from cross-origin blocking when attempting to pull remote coordinate data directly on the client side. I overcame this by configuring our Express server to function as an authenticated backend proxy route (/api/ai/weather), masking external requests through the server environment.
  3. Deployment Platform Nuances: Deploying the live Node.js cluster within a hosted shared cPanel environment threw severe database driver runtime crashes due to low-level environment runtime variations (such as missing global crypto modules in older Node environments). I systematically debugged this by refactoring how environment files handled conditional fallbacks between local environments and cloud targets, securing reliable up-times for our live application.

Accomplishments that I am proud of

  • True Tool Integration via MCP: Successfully moving beyond simple API prompt injection by building a functional Model Context Protocol loop. Seeing the Gemini agent successfully query collections and reason across historical logs before speaking to a farmer is a massive milestone.
  • 9-Language Polyglot Support: Building an audio text-to-speech processing structure that seamlessly translates complex technical climate data into regional languages like Yoruba, Igbo, and Hausa, ensuring accessibility for non-literate communities.
  • Fluid Performance: Creating a responsive, data-heavy Vue 3 workspace that maintains fluid frame rates even while handling heavy telemetry arrays, Leaflet maps, and real-time Apex charts simultaneously.

What I learned

  • The Power of MCP Standards: I discovered how much development overhead is removed when you give an LLM standardized tool layers like MCP. It proved that instead of building complex endpoint routers, we can describe our schema and let the model select tools on demand.
  • Resilient Error Fallbacks: I learned how critical it is to design failure handling routines for external web endpoints. If a remote climate API experiences downtime, an agent must gracefully catch the exception, rely on cached historical states, and alert the user without crashing the thread.
  • State Control Management: Designing multi-step agents requires tight state boundaries. I learned how to write system guidelines that ensure Gemini uses tools accurately without looping unnecessarily.

What's next for AgriClimate AI Agent

  • Edge Sensor Integration: I plan to move beyond public weather services by deploying actual physical IoT hardware nodes (ESP32 microcontrollers measuring soil NPK, moisture, and ground telemetry) that stream data directly to MongoDB instances via secure ingestion hooks.
  • Offline Agent Actions: Implementing progressive web app capabilities combined with compressed local fallback models to allow farmers deep in rural locations with limited internet connections to access emergency agricultural advice.
  • Community Threat-Sharing: Creating an automated alert broadcast system where if the agent detects a high probability of an outbreak on one farm, it can drop an anonymous localized alert marker onto the shared map, warning nearby smallholders within a 15-kilometer radius to take preemptive action.

Built With

Share this project:

Updates