DEV Community

PRASAD TILLOO
PRASAD TILLOO

Posted on

How I Built a Behavioral Nudge Engine for Farmers on Serverless AWS

Read the full article on AWS Builder Center

Every agricultural AI chatbot I found had the same blind spot: they stop at information delivery.

They tell the farmer what to do. None of them know whether the farmer actually did it.

That gap — between knowing and doing — is where crop loss happens. A cotton farmer in Maharashtra (India) who misses a 3-day insecticide / pesticide spray window can lose 30-50% of his crop. Not because the advice doesn't exist in FAO and ICAR research manuals — but because it never reaches him in time, in his language, in a format he can act on.

So I built AgriNexus AI — a WhatsApp-based agricultural advisor that goes beyond Q&A. It proactively sends weather-timed nudges and follows up until the farmer confirms: "ho gaya" (done).

The Problem vs The Solution — AgriNexus bridges the last mile

Built for the AWS 10,000 AIdeas competition. Full article with demo videos on AWS Builder Center.


The Architecture: Four Flows, One WhatsApp Number

AgriNexus supports four interaction modes — all through the WhatsApp number the farmer already has:

AgriNexus AI — Four capabilities on one platform

1. Text Chat — Farmer types in Hindi, Marathi, Telugu, or English. Amazon Bedrock RAG searches FAO and ICAR manuals, Claude 3 Sonnet generates a response in the farmer's language with source citations. 3-5 seconds end-to-end.

2. Voice Pipeline — Farmer sends a voice note describing crop symptoms. The pipeline: OGG audio from WhatsApp → S3 → Amazon Transcribe (dialect-matched: hi-IN, mr-IN, te-IN, en-IN) → transcript re-queued to the same RAG pipeline → Claude 3 Sonnet response → Amazon Polly neural TTS → audio + text reply back. The farmer hears the answer while walking the field.

3. Crop Vision — Farmer photographs a diseased leaf. Claude 3 Sonnet Vision identifies the pest/disease, returns a structured diagnosis: pest name, confidence score, recommended pesticide, dosage, application timing, and safety warnings. All in the farmer's language.

Crop photo in → pest ID, dosage, safety warning out

4. The Nudge Loop — This is what makes AgriNexus different from a chatbot. More on this below.


The Behavioral Nudge Engine: From Knowledge to Action

This is the core innovation. Every other agricultural AI tool I studied — Farmer.Chat, iSDA, AgriChat.AI — stops at information delivery. AgriNexus closes the loop.

Closing the behavior gap — from knowledge to action

The nudge engine doesn't wait for the farmer to ask. When weather conditions are right for spraying, it initiates contact:

  1. EventBridge Scheduler triggers WeatherPoller Lambda daily at 7 AM
  2. WeatherPoller checks conditions: wind < 15 km/h, no rain forecast
  3. If conditions pass → Step Functions nudge workflow starts
  4. Workflow queries DynamoDB for eligible farmers by region + crop + consent (with duplicate prevention — no farmer gets two nudges for the same activity on the same day)
  5. NudgeSender Lambda fires a crop-specific WhatsApp message with interactive buttons

The farmer sees (in Hindi):

"Today is good weather for fungicide spray on wheat. Wind: 8 km/h."
[Done] [Not now]

If they tap "ho gaya" (done) — DynamoDB Streams triggers ResponseDetector Lambda, which detects the DONE keyword across all supported languages (Hindi/Marathi/Telugu/English), cancels all pending reminders, and marks the nudge as COMPLETED.

If they don't respond — reminders fire at T+24h and T+48h.

Farmer confirms vs farmer delays — the closed loop in action

The Architecture Decision That Saved Us: EventBridge Scheduler vs Step Functions Wait States

This was the most interesting trade-off in the build.

The naive approach: keep a Step Functions execution alive for 72 hours to handle T+24h and T+48h reminders. At scale, that's expensive — state transition costs accumulate, and you're paying for executions that idle for days.

The AgriNexus approach: Step Functions workflow completes in under 5 seconds. It sends the nudge and registers EventBridge Scheduler targets for each reminder. When the farmer responds, ResponseDetector deletes those schedules instantly. Short execution + scheduled targets = clean, cheap, scalable.

EventBridge Scheduler vs Step Functions Wait States

This pattern is reusable for any system that needs delayed follow-ups with early cancellation — appointment reminders, SLA escalations, onboarding sequences.


The Nudge Loop Architecture

Here's the full flow diagram — 12 steps from weather check to loop closure:

Nudge Loop Architecture — from weather check to farmer confirmation
Key components:

  • EventBridge Scheduler — 7 AM daily trigger + T+24h/T+48h reminder targets
  • Step Functions — orchestrates the nudge workflow (completes in seconds, not days)
  • DynamoDB Streams — real-time DONE keyword detection without polling
  • ResponseDetector Lambda — multi-language keyword matching + schedule cleanup
  • Single-Table DynamoDB — user profiles, message idempotency, and nudge tracking in one table with composite keys

Five Architecture Decisions in 30 Seconds

  1. Single-Table DynamoDB — composite keys (PK=USER#<phone>, SK=PROFILE|MSG#<ts>|NUDGE#<id>) with GSI for region-based targeting. Access patterns defined before schema.

  2. EventBridge Scheduler over Step Functions Wait States — short-lived executions + scheduled targets. Event-driven cleanup on DONE detection.

  3. DynamoDB Streams for real-time response detection — no polling. Stream triggers Lambda on every write, checks for DONE keywords across 4 languages.

  4. Claude 3 Sonnet for code-switching — farmers mix Hindi and English ("Mere cotton mein pests hain"). Don't over-engineer language detection. Let the model handle what it's trained for.

  5. Batch transcription over streaming (MVP) — 20-34 second latency is acceptable for async WhatsApp. Ship first, optimize with real user feedback. Transcribe Streaming (<2s) is the post-MVP path.


The Stack

Layer Technology
Messaging WhatsApp Business API + API Gateway
Intelligence Amazon Bedrock (Claude 3 Sonnet) + RAG
Knowledge Base Bedrock Knowledge Bases + OpenSearch Serverless
Voice In Amazon Transcribe (hi-IN, mr-IN, te-IN, en-IN)
Voice Out Amazon Polly (Aditi/Kajal neural voices)
Vision Claude 3 Sonnet multimodal
Nudge Engine EventBridge Scheduler + Step Functions + DynamoDB Streams
Storage DynamoDB single-table + S3
Orchestration AWS SAM, Lambda (Python 3.11)

Fully serverless. Zero instances. Scales from 10 to 10,000 farmers without re-architecture. Under $0.70/farmer/year at 10,000 users.


What I Learned

Voice is the interface, not a feature. Typing in Devanagari on a basic Android is slow and error-prone. Voice notes are what farmers already use to communicate with family. AgriNexus works the same way.

Behavioral nudges need closed loops. Sending a reminder is easy. Knowing whether it worked is hard — and it matters. The T+24h/T+48h chain with DONE/NOT YET buttons came from thinking about what actually changes behavior, not just what delivers information.

Prompt engineering is iterative. Initial RAG prompts gave 60% accuracy. Structured prompts with explicit format instructions and language-specific system messages reached 95%. Treat the AI as a collaborator that needs clear instructions.

Event-driven beats polling. DynamoDB Streams for DONE detection, EventBridge Scheduler for delayed reminders, SQS for async processing — events scale better than polling loops at every level.


Try It / Read More

I built AgriNexus for the AWS 10,000 AIdeas competition (Agriculture & Food Security category) using Kiro for spec-driven development and 100+ EARS requirements with full traceability to code.

The full technical deep-dive with demo videos, all four architecture flow diagrams, cost analysis, and the complete build journey is here:

Read the full article on AWS Builder Center

GitHub: AgriNexus AI

If this resonated — a like on the article puts an AI agronomist in one more farmer's pocket 🙏 Voting closes March 20.


Built with Amazon Bedrock, Kiro, AWS Lambda, DynamoDB, EventBridge Scheduler, Step Functions, SQS FIFO, and WhatsApp Business API.

Top comments (0)