AgriAgent: Harvesting Fair Value with Agentic AI

đź’ˇ Inspiration

Agriculture is the backbone of our economy, yet farmers are frequently the most marginalized stakeholders in the supply chain. Time and time again, we see farmers forced to sell their Grade-A crops at rock-bottom prices to middlemen simply because they lack access to real-time market insights and negotiation power. Furthermore, technological barriers—like complex typing interfaces and language barriers—keep them entirely excluded from modern digital marketplaces.

I was inspired to build AgriAgent to solve this exact real-life problem. I wanted to create an ecosystem that doesn't just display data, but acts as a dedicated, intelligent advocate for the farmer. The goal was to build a platform that can "see" crop quality, "speak" to the farmer, and intelligently "negotiate" on their behalf.

⚙️ How I Built It

The application was built as a modern, full-stack web application designed for a frictionless user experience:

  • Frontend Ecosystem: I used React to build a dynamic single-page application. To ensure the app immediately grabbed the judges' attention, I implemented a highly premium, glossy "glassmorphism" UI using Tailwind CSS.
  • Accessibility First (AgriVoice): I integrated the native webkitSpeechRecognition (Web Speech API) directly into the frontend. This captures voice commands and sends them to the backend, bypassing the need for manual data entry.
  • Backend & Agentic Logic: The server runs on Node.js/Express. It handles complex prompt engineering to transform user data, images, and voice inputs into actionable marketplace listings.
  • The AI Layer: I utilized OpenAI's GPT-4o-mini and Vision APIs to power three core engines:
  • The Crop Quality Grader (image analysis).
  • The Market Trend Predictor.
  • The Bidding Mediator (Agentic Negotiator).

To formalize the AI's internal market valuation strategy for the Negotiator and Market Predictor, the backend logic loosely follows an expected-value optimization model. The predicted fair price $P_{fair}$ for a given time $t+1$ is calculated based on the base price, the AI-derived quality score ($Q$), and the dynamic market trend coefficient ($\alpha$):

$$P_{fair}^{(t+1)} = \left( \sum_{i=1}^{n} P_{historical}^{(i)} \cdot w_i \right) \times \left( 1 + \alpha \cdot \frac{Q}{100} \right)$$

For the bidding mediator, the AI is constrained to accept an offer $O_{buyer}$ if and only if it satisfies the condition:

$O_{buyer} \geq P_{fair} - \epsilon$ (where $\epsilon$ is the acceptable margin of negotiation, configured within the LLM prompt).

⚠️ Challenges I Faced

  • Database Architecture Pivot: Midway through development, I realized that relying on a cloud database could introduce latency and connection risks during a live demo. I made the strategic decision to completely strip out cloud dependencies and pivot to a strictly local, in-memory database system. Applying core concepts from Data Structures and Algorithms, I engineered the local state to handle the data arrays efficiently so the app remained lightning-fast.
  • Environment Constraints: Setting up and testing the full Node.js and React stack, along with managing API securely, entirely on my Kali Linux environment required careful configuration of ports and environment variables.
  • Agentic Constraints: Training the AI Negotiator to be "polite but firm" was challenging. It took extensive prompt tuning to ensure the AI wouldn't just accept any lowball offer, but would instead calculate the counter-offer accurately and advocate fiercely for the farmer.

đź§  What I Learned

  • Building Agentic Workflows: I learned how to move beyond simple LLM text generation and actually use AI as an active "Agent" (the Negotiator) that makes conditional decisions based on user input.
  • Seamless Hardware-to-Web Integration: Implementing the Web Speech API taught me how to bridge physical inputs (microphone) with generative AI to create a flawless accessibility tool.
  • Security & Error Handling: With my background as a bug bounty hunter, I took extra care to implement rigorous try-catch blocks and mock-data fallbacks across all API endpoints. I learned how to build a crash-proof frontend that degrades gracefully if an API key fails, ensuring the user experience is never broken.

🚀 What's Next for AgriAgent

The MVP successfully demonstrates the power of an AI advocate for farmers. In the future, I plan to integrate localized language models (so farmers can negotiate fully in regional dialects) and deploy the backend to a scalable microservices architecture. I also plan to package the platform as a Progressive Web App (PWA) so farmers can access the voice features natively from low-end smartphones.

Built With

  • express.js-artificial-intelligence:-openai-api
  • frontend:-react
  • gpt-4o-mini
  • local-state-(dsa-optimized)-development-environment:-kali-linux
  • next.js
  • openai-vision-api-apis-&-integrations:-web-speech-api-(for-agrivoice)
  • restful-apis-database-&-state-management:-in-memory-data-structures
  • tailwind-css-backend:-node.js
Share this project:

Updates