It started with a photograph. Three weeks before the hackathon, one of our team members visited his uncle's farm in the Souss-Massa region — the agricultural heart of Morocco. His uncle, a small-scale tomato farmer with 2 hectares and 20 years of experience, pointed to a row of wilting plants.

"I don't know what this is," he said in Darija. "The leaves are yellowing from the bottom. I tried the treatment my neighbor used. It didn't work. Now I've lost 30% of this row."

He couldn't afford an agronomist — 500 Dirhams for a consultation, plus 3 days of waiting. The local agricultural extension office was 40 kilometers away. His phone had a camera, but no app could tell him what he was seeing.

That night, we asked ourselves a question:

"What if Gemini could be that agronomist?"

Not a chatbot. Not a translator. A reasoning agent that could see what the farmer sees, speak the way the farmer speaks, and recommend treatments the farmer can actually buy — at the local souk, in Dirhams, today.

That question became Fellah.AI. 🧠 What We Learned

  1. Language Is Not Translation — It's Reasoning We initially thought the challenge was translating between Darija, French, and Arabic. We were wrong.

The real challenge is reasoning across languages. A farmer doesn't say "My tomato plant exhibits chlorosis on the lower foliage." They say "tomatich bdat tsfar mn taht."

We learned that Gemini's multilingual capability isn't just about vocabulary — it's about register. The model needs to know when to be formal (market advice) and when to be warm (emergency diagnosis). We solved this with few-shot examples embedded as assistant messages, priming the model to code-switch naturally between Darija, French, and Arabic without sounding robotic.

  1. Vision Without Reasoning Is Useless

Many plant diagnosis apps exist. They do image classification → output disease name → stop. That's not how a real agronomist works.

A real agronomist: Observes the entire plant (leaves, stems, fruit, distribution pattern) Hypothesizes 2-3 possible causes ranked by likelihood Contextualizes with season, weather, irrigation, recent treatments Concludes with confidence

Acts with specific, local, affordable interventions

We learned to build this 4-stage cognitive chain into our prompt architecture — not as a single instruction, but as separate API calls where each stage's output feeds the next. This is what makes Fellah.AI feel intelligent, not just automated.

  1. The Long Context Window Is a Superpower

Gemini's 1 million token context window is the most underutilized feature in hackathon projects. Most teams ignore it. We built our entire session persistence strategy around it.

We learned to inject persistent farmer profiles — name, land size, water source, budget, crop portfolio, market prices — into the context at session start. The model never asks for information already provided. It remembers the farmer's history across the entire conversation.

But we also learned the hard way: context windows fill up. We built a 3-mechanism token rupture prevention system — rolling summaries, priority preservation, and Firestore checkpoints — so the farmer never loses their session, even after 100 exchanges.

  1. Structured Output Builds Trust Farmers don't want prose. They want answers.

We learned to force Gemini to output strict JSON with fields that matter: diagnosis, confidence (1-5), urgency (1-5), evidence[], differential[], intervention_steps, follow_up_days, and a disclaimer in three languages.

This turned a "magic black box" into a transparent, auditable, actionable system. The farmer can see why the model made its recommendation. The judge can see that we thought about production, not just demo. 🛠️ How We Built It The Stack Layer Technology Why AI Engine Gemini 2.5 Flash (Vertex AI) Vision + language + 1M context in one model Agent Framework Google ADK Built-in session management, artifact storage, reasoning planner Backend FastAPI (Python) Async, Pydantic validation, Cloud Run ready Frontend Gradio Chat + image upload + JSON display in 20 lines Database Firestore (Native) Serverless, session persistence, vector search for RAG Storage Cloud Storage Plant images, session artifacts Hosting Cloud Run Auto-scales from 0 → unlimited, pay per request The 4-Stage Diagnosis Chain

This is the core innovation. Each stage is a separate Gemini call:

Stage 2A forces pure observation — no conclusions yet. Stage 2B generates 3 hypotheses with ruling features. Stage 2C injects season, location, weather, recent treatments. Stage 2D outputs production-ready JSON with local product names and Dirham prices. The Cultural Calibration

We embedded few-shot examples of authentic Moroccan Darija as assistant messages before any farmer input: text

Farmer (Darija): "chwiya d tomatich bdat tsfar, wach ndir?" Fellah.AI: "Salam! Sfra di, wach kayna mn fok wlla mn taht?..."

This primed the model to match the farmer's register — warm, direct, neighborly — not formal Modern Standard Arabic. The Token Rupture Prevention

We built a 3-mechanism system into ADK's session service: Rolling summary every 10 exchanges → compress history to JSON Priority preservation → never drop farmer profile, crop portfolio, market prices Firestore checkpoints every 5 exchanges → full session recovery on crash

This was the hardest technical challenge, but it's what makes the system production-viable for real farmers with long conversations. ⚠️ Challenges We Faced Challenge 1: Gemini Wanted to Speak Fus'ha (Formal Arabic)

The problem: When we first prompted in Darija, Gemini defaulted to Modern Standard Arabic — grammatically correct, but culturally distant. A farmer would feel like they were talking to a bureaucrat, not a neighbor.

The solution: We stopped using system prompt instructions alone. We switched to few-shot priming — inserting 3 authentic conversation examples as assistant messages before the farmer's first input. This calibrated the model instantly. Now it code-switches naturally. Challenge 2: The 4-Stage Chain Was Too Slow

The problem: Four separate API calls = 4x latency. The first version took 24 seconds from image upload to diagnosis — unacceptable for a farmer in the field.

The solution: We optimized three ways: Switched from Gemini Pro to Gemini 2.5 Flash (4x faster, 1/10th the cost) Made Stage 2A and 2B parallelizable (run concurrently, share visual embedding) Cached the regional context between calls instead of re-injecting

Final latency: 8 seconds from upload to JSON. Challenge 3: Product Availability Was Hallucinated The problem: Gemini recommended excellent fungicides — that don't exist in Morocco. Or exist only in Casablanca, 500km from Agadir.

The solution: We built a constrained product database into the prompt: Hard-coded 50 most common products available at Marché de gros Agadir Added budget categories (Low/Medium/High) in Dirhams Added an organic alternative option for each Instructed the model: "If product is not in this list, say 'Consult local agronomist' — do not hallucinate"

This turned a weakness (model hallucination) into a strength (ethical guardrails signal responsible AI design). Challenge 4: Context Ruptured Mid-Demo The problem: During our first live test, after 15 exchanges, the model suddenly forgot the farmer's crop. It started giving citrus advice to a tomato farmer. This would have been a disaster during judging.

The solution: We implemented the Rupture Detection Probe — a hidden validation check after every 5 turns that asks the model three questions from memory. If it fails any, we reload from the latest Firestore checkpoint and resume seamlessly. The farmer never sees the interruption. 📊 The Results Metric Traditional Agronomist Fellah.AI Cost 500 DH 0 DH Wait time 3 days 8 seconds Language Formal Arabic/French Darija, French, or Arabic (farmer's choice) Products Generic names Moroccan brand names + price in DH + souk location Session memory Human recall Persistent across weeks (Firestore) Confidence transparency Tacit Explicit (1-5 scale + differential)

🌍 What's Next Fellah.AI is not a hackathon project. It's a production system designed for the 1.5 million small-scale farmers of Morocco.

Next 30 days: Field testing with 50 farmers in Ait Melloul, Biougra, and Tiznit Expand product database to 500 SKUs with real-time souk prices Add voice input for farmers with low literacy

Next 6 months: WhatsApp integration (the most common digital channel for Moroccan farmers) Local language TTS for Darija output Pest outbreak prediction using Gemini's long context + seasonal patterns

Next 2 years: Scale to North and West Africa (Tunisia, Senegal, Ivory Coast) Build the first Darija agricultural knowledge graph Partner with Ministry of Agriculture for national deployment

🏆 Why We Deserve the Gemini API Prize

"We used every dimension of what makes Gemini unique —
vision, long context, multilingual reasoning, and structured output —
in a single coherent system that would be impossible to build with any other model,
serving 1.5 million Moroccan farmers who have never had access to this kind of intelligence before."

Fellah.AI is not a chatbot. It is a cognitive architecture: A 4-stage reasoning chain mirroring expert agronomist workflow Token rupture prevention for sessions that last hours Cultural calibration to Darija through few-shot priming Structured JSON output with confidence, evidence, and local interventions We built this in 8 hours. But we designed it for 1.5 million farmers. Fellah means farmer. Fellah also means success.

That's the promise. 🙏 Acknowledgments Google Developer Group Agadir for hosting Hack Days MLH for the mentorship and infrastructure Universiapolis Agadir for the space and support Every small-scale farmer in Souss-Massa who shared their stories, their struggles, and their land فلاح • Fellah.AI • Hack Days Agadir 2026

Built With

Share this project:

Updates

Submission history